Reputation: 6751
I am trying to add SVN revision number in the manifest of my projects. To do so, I used Maven build number plugin and added the following lines in my Super POM:
<!-- Gets the SVN revision number -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<providerImplementations>
<svn>javasvn</svn>
</providerImplementations>
</configuration>
</plugin>
<!-- Add the SVN revision number in the manifest (works on Hudson only) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
</manifestEntries>
</archive>
</configuration>
</plugin>
Note the configuration:
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
I did that on purpose because if I have local modifications "doCheck" will prevent me from compiling (and I want to compile and test BEFORE commiting my work).
The "doUpdate" is also a problem for me as I don't necessarily want to update the code from repository. Same reason than above, I want to test locally before commiting (and potentially solving conflicts).
My problem is that in the manifest, what appears is:
Implementation-Build: ${buildNumber}
Thus the variable is not interpreted. What did I miss?
Thanks
Edit: The problem is in fact with maven-bundle-plugin. I use it in my projets to generate OSGi bundles.
The POM packaging of the projects is thus:
<packaging>bundle</packaging>
Instead of:
<packaging>jar</packaging>
I guess this messes with the Maven lifecycle. When I remove the maven-bundle-plugin everything works fine. But I cannot remove it as my applications are OSGi apps.
Upvotes: 4
Views: 1216
Reputation: 21
Instead of using configuration/archive try using configuration/instructions to add your ${buildNumber}, like this:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Implementation-Build>${buildNumber}</Implementation-Build>
</instructions>
</configuration>
</plugin>
With your approach and Maven 2, it all worked. We switched to Maven 3, the maven-bundle-plugin was not happy (same behavior as yours). This approach did the trick.
Upvotes: 2
Reputation: 6751
The problem was mixing maven-bundle-plugin and maven-jar-plugin to manipulate the Jar MANIFEST.
The solution:
In the Super POM:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Implementation-Build>${buildNumber}</Implementation-Build>
</instructions>
</configuration>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
<!-- Gets the SVN revision number -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<providerImplementations>
<svn>javasvn</svn>
</providerImplementations>
</configuration>
-</plugin>
</plugins>
</build>
And that's it!
Upvotes: 2
Reputation: 48105
You can make use of Maven Plugin Management.
Add your plugin definitions in the super pom under <pluginManagement/>
like so:
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<providerImplementations>
<svn>javasvn</svn>
</providerImplementations>
</configuration>
</plugin>
<!-- Add the SVN revision number in the manifest (works on Hudson only) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
...
</project>
And then in the project where you want to use these now configured plugins you add this to the poms:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
...
</project>
That should sort it out for you.
Upvotes: 0