Property autocapitalization in maven

前端 未结 2 1595
萌比男神i
萌比男神i 2021-01-13 20:47

I have a maven project that requires a property to be set at the command line(-Dmy.property=val). What I need to do is to convert that string into all caps since that proper

相关标签:
2条回答
  • 2021-01-13 21:13

    With following code, MY_PROPERTIES equals to uppercased value of 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>      
    
    0 讨论(0)
  • 2021-01-13 21:27

    The groovy plugin could be used. 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>
    
    0 讨论(0)
提交回复
热议问题