javasvnmavenbuildnumber-maven-pluginmaven-bundle-plugin

Error while adding SVN revision in JAR manifest with Maven and maven-bundle-plugin


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.


Solution

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