Autocapitalization of property in maven

I have a maven project that needs to set a property on the command line (-Dmy.property = val). I need to do this to convert this string to all caps, as this property is used to replace strings in multiple files through the maven-resources-plugin. What is the easiest way to do this?

+3
source share
2 answers

You can use the groovy plugin. The following configures it to run at the beginning of the Maven build process:

        <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>
+10
source

With the following code MY_PROPERTIEScorresponds to the upper value 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>      
+1
source

All Articles