1

We have a multi module java project where we have pom.xml in every modules. I see we have ${project.version} in pom.xml which basically gets the project version. Is there anything like ${project.version.prefix} which will also gets the project version minus SNAPSHOT?

2 Answers 2

3

use build-helper-maven-plugin (via build helper plugin not parsing project version)

maven-antrun-plugin used only to show results

 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.7</version> <executions> <execution> <phase>validate</phase> <id>parse-version</id> <goals> <goal>parse-version</goal> </goals> <configuration> <propertyPrefix>parsedVersion</propertyPrefix> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.1</version> <executions> <execution> <phase>validate</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo>Major: ${parsedVersion.majorVersion}</echo> <echo>Minor: ${parsedVersion.minorVersion}</echo> <echo>Incremental: ${parsedVersion.incrementalVersion}</echo> <echo>Qualifier: ${parsedVersion.qualifier}</echo> <echo>BuildNumber: ${parsedVersion.buildNumber}</echo> <echo>Project version: ${project.version}</echo> <echo>No qualifier: ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}</echo> </tasks> </configuration> </execution> </executions> </plugin> 

Output:

 [INFO] --- maven-antrun-plugin:1.1:run (default) @ XXX --- [INFO] Executing tasks [echo] Major: 1 [echo] Minor: 2 [echo] Incremental: 0 [echo] Qualifier: SNAPSHOT [echo] BuildNumber: 0 [echo] Project version: 1.2.0-SNAPSHOT [echo] No qualifier: 1.2.0 
Sign up to request clarification or add additional context in comments.

Comments

0

There isn't anything inherent in Maven that you can use for this, but you can configure the build-helper-maven-plugin to set a property where you can parse out the data.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.