5

我有一个需要在命令行设置属性的 maven 项目(-Dmy.property=val)。我需要做的是将该字符串转换为全部大写,因为该属性用于通过 maven-resources-plugin 在许多文件中进行字符串替换。最简单的方法是什么?

4

2 回答 2

13

可以使用 groovy 插件。以下将其配置为在 Maven 构建过程开始时运行:

        <plugin>
            <groupId>org.codehaus.groovy.maven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <version>1.0</version>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <goals>
                        <goal>execute</goal>
                  </goals>
                   <configuration>
                      <source>
                      import org.apache.commons.lang.StringUtils

                      project.properties["my.property"] = StringUtils.upperCase(project.properties["my.property"]) 
                     </source>
                 </configuration>
             </execution>
          </executions>
     </plugin>
于 2012-05-09T19:05:52.547 回答
5

使用以下代码,MY_PROPERTIES等于 的大写值my.properties

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>1.12</version>
  <executions>
    <execution>
      <id>properties-to-uppercase</id>
      <goals>
        <goal>regex-property</goal>
      </goals>
      <configuration>
        <name>MY_PROPERTY</name>
        <regex>.*</regex>
        <value>${my.property}</value>
        <replacement>$0</replacement>
        <failIfNoMatch>false</failIfNoMatch>
        <toUpperCase>true</toUpperCase>
      </configuration>
    </execution>
  </executions>
</plugin>      
于 2017-01-12T09:41:38.633 回答