Skip to content

Instantly share code, notes, and snippets.

@chbaranowski
Created May 13, 2011 16:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chbaranowski/970877 to your computer and use it in GitHub Desktop.
Save chbaranowski/970877 to your computer and use it in GitHub Desktop.
Replace a String value of a property in Apache Maven (Workaround)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.seitenbau.demo.maven</groupId>
<artifactId>maven-properties-replace</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<!-- modify content of a maven property and save it into a new property
via Groovy Maven Plugin ... -->
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
System.setProperty("versionWithOutPrefix", "${version}".replace('-SNAPSHOT', ''))
</source>
</configuration>
</execution>
</executions>
</plugin>
<!-- Sample how to use the new property versionWithOutPrefix-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<target>
<echo message="info the version is: ${version} "/>
<echo message="info the version without SNAPSHOT pefix is: ${versionWithOutPrefix} "/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment