1

I have a project where I have a need to break the version number down and access it's component pieces when building a manifest file. After doing some searching around I found the build-helper-maven-plugin and figured my problem was solved. I added the plugin to the master POM, it's shown below.

 <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> 

The project version at this point in time is 3.0.0-SNAPSHOT. I wanted to see all the pieces (although in the final version I may not use them all) so I added these lines to my manifest file.

<value name="majorVersion">${parsedVersion.majorVersion}</value> <value name="minorVersion">{$parsedVersion.minorVersion}</value> <value name="incrementalVersion">${parsedVersion.incrementalVersion}</value> <value name="versionQualifier">${parsedVersion.qualifier}</value> <value name="parsedBuildNumber">${parsedVersion.buildNumber}</value> 

After building I get this.

<value name="majorVersion">0</value> <value name="minorVersion">{$parsedVersion.minorVersion}</value> <value name="incrementalVersion">0</value> <value name="versionQualifier">3.00.0-SNAPSHOT</value> <value name="parsedBuildNumber">0</value> 

The value tag is actually an XML tag and there is a closing value tag in the manifest file, I had to remove them since they were messing up the display.

So the incremental version appears to be correct, although I'm not all that confident given that the major version isn't correct, it found no minor version, and the qualifier comes back as the entire version number, rather than just the SNAPSHOT piece i had expected. I can see where a build number of zero would be correct since we don't have what Maven considers a build number.

Any ideas on why the version number doesn't seem to be parsing? Have I implemented this plugin incorrectly?

thanks steve

1 Answer 1

7

Change {$parsedVersion.minorVersion} to ${parsedVersion.minorVersion}


When are you inspecting the property values? Ensure you're doing it after the validate phase in your example, or if you want it on the same phase ensure the build-helper-maven-plugin occurs before the plugin you're using to inspect the property values. If I have this:

 <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> </tasks> </configuration> </execution> </executions> </plugin> 

after the build-helper-maven-plugin, I see this in the output of mvn validate:

[INFO] --- build-helper-maven-plugin:1.7:parse-version (parse-version) @ so-example --- [INFO] [INFO] --- maven-antrun-plugin:1.1:run (default) @ so-example --- [INFO] Executing tasks [echo] Major: 1 [echo] Minor: 0 [echo] Incremental: 0 [echo] Qualifier: SNAPSHOT [echo] BuildNumber: 0 anew@buddha:~/dev/so-example$ grep "<version>" pom.xml | head -1 <version>1.0.0-SNAPSHOT</version> 
Sign up to request clarification or add additional context in comments.

6 Comments

That's for catching the typo on the minor version, I was looking right past that. Now I get zeroes for all pieces, major, minor, incremental, which isn't right, but I'm at least getting some values so it's a step
I added a note about inspecting the property values, hope it helps.
The filtering or use of the version information is happening at the assembly step. It's a file set with filtering on.
I have explicitly added the phase to the helper plug-in so it happens at validate. I did add some echo's to the our maven-antrun-plugin section just to see the output's and they are the same as in the actual manifest file, zero for major, minor, and incremental version numbers as well as the build number. The full version for the qualifier (the full version is 3.0.0-SNAPSHOT).
Just a thought -- is your parent pom's version 0.0.0? Otherwise it sounds like a bug, or another plugin is somehow interfering with the effective pom at execution time.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.