3

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.

Ben
  • 6,321
  • 9
  • 40
  • 76
  • Sorry to say but that code example of yours works perfectly fine for me. But I haven't put that in a Super Pom. Just straight into the pom that is creating the jar. Have you put the plugins in `` or directly under ``? – maba Sep 26 '12 at 15:47
  • 1
    directly under Maybe it comes from the fact that it is in the super pom... But I don't want to edit all the POMs of all the projects that inherit from this super POM... – Ben Sep 26 '12 at 16:41

3 Answers3

2

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.

1

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!

Grzegorz Grzybek
  • 6,152
  • 3
  • 29
  • 42
Ben
  • 6,321
  • 9
  • 40
  • 76
0

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.

maba
  • 47,113
  • 10
  • 108
  • 118
  • I tryed that... I still get the "Implementation-Build: ${buildNumber}" uninterpreted tag in the manifest... – Ben Sep 27 '12 at 07:26
  • @Ben Test with the `` example from [this usage page](http://mojo.codehaus.org/buildnumber-maven-plugin/usage.html). Try to see if your jar file will include the buildnumber in the name. – maba Sep 27 '12 at 07:34
  • I tried it: added "buildnumber-maven-plugin-1.1-r${buildNumber}" in the POM of my module (not the Super POM). It created the following JAR in the target directory: buildnumber-maven-plugin-1.1-r${buildNumber}.jar – Ben Sep 27 '12 at 07:50
  • OK, hard to tell why it is not working. Try to set another property name than `buildNumber`. Maybe some name clashing. Use this tag in the configuration: `myOwnBuildNumberName` and use that property instead. – maba Sep 27 '12 at 07:58
  • I tried that too... In the Super POM: ` false false javasvn myOwnBuildNumberName ` Still in the Super POM, in the Manifest section: `${myOwnBuildNumberName}-${pom.artifactId}`. – Ben Sep 27 '12 at 08:58
  • Then in the module POM: `${myOwnBuildNumberName}` I end up with a jar called `${myOwnBuildNumberName}.jar`, which MANIFEST contains `Implementation-Build: ${myOwnBuildNumberName}-org-test-module`. Just an unrelated question: how do you force line breaks in comments? – Ben Sep 27 '12 at 09:02
  • I also tried to put everything in the module POM (and thus nothing in the Super POM... same result – Ben Sep 27 '12 at 09:06
  • Two other remarks. 1) In Maven output, it says `[INFO] Change the default 'svn' provider implementation to 'javasvn'. [INFO] Checking for local modifications: skipped. [INFO] Updating project files from SCM: skipped. [INFO] Storing buildNumber: 820 at timestamp: 1348736818571 [INFO] Storing buildScmBranch: trunk` 2) I also use Maven-Bundle-Plugin to generated OSGi modules... Could it interfere? ` – Ben Sep 27 '12 at 09:09
  • @Ben You cannot force line breaks. A comment is just a comment. If you want to show some more/new code then update the question with the new information. – maba Sep 27 '12 at 09:29
  • @Ben Regarding the problem I don't know if I have much more to help you with. Try to skip the bundle plugin and see if that helps. As the log file tells you the buildNumber is there so that part works. – maba Sep 27 '12 at 09:30
  • I did remove the bundle plugin. I also had to change packaging from `bundle` to `jar`... And it worked! Maybe the problem is with the "bundle" packaging? – Ben Sep 27 '12 at 09:36
  • @Ben Good for you! I am not using the `maven-bundle-plugin` so I cannot really tell. Regarding my answer I think you should be looking at using the `` tag. It is very useful. – maba Sep 27 '12 at 09:38
  • Not that good. If I remove the maven-bundle-plugin, my application cannot work... So right now I have two choices, either retrieve SVN revision or have a working application... :-) – Ben Sep 27 '12 at 09:49