0
votes

I'm trying to put the build number in the MANIFEST.MF of my EAR, based on the revision number retrieved from SCM (svn in this case). I have a maven parent project with some nested project, one of which is responsible of creating the EAR.

This is my parent pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                          http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <properties>
        <sourceVersion>1.8</sourceVersion>
        <targetVersion>1.8</targetVersion>
    </properties>
    <scm>
        <connection>scm:svn:svn://name.surname@serverName/example/branches/tryRevision</connection>
    </scm>
    <modules>
        ...
        <module>app-ear</module>
    </modules>

    <build>
        <!-- plugins used by this POM and all inheriting POMs -->
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>buildnumber-maven-plugin</artifactId>
                    <version>1.4</version>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>create</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <doCheck>false</doCheck>
                        <doUpdate>false</doUpdate>
                        <revisionOnScmFailure>no-revision</revisionOnScmFailure>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-scm-plugin</artifactId>
                    <version>1.9.5</version>
                    <configuration>
                        <connectionType>connection</connectionType>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

and this is the app-ear/pom.xml:

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <parent>
        <groupId>com.example</groupId>
        <artifactId>app</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>app-ear</artifactId>
    <packaging>ear</packaging>
    <build>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                    <configuration>
                        <source>${sourceVersion}</source>
                        <target>${targetVersion}</target>
                        <verbose>true</verbose>
                        <fork>true</fork>
                        <executable>${compilerLocation}</executable>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>buildnumber-maven-plugin</artifactId>
                    <version>1.4</version>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>create</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <doCheck>false</doCheck>
                        <doUpdate>false</doUpdate>
                        <revisionOnScmFailure>no-revision</revisionOnScmFailure>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-ear-plugin</artifactId>
                    <version>2.10.1</version>
                    <configuration>
                        <skinnyWars>true</skinnyWars>
                        <finalName>myapp</finalName>
                        <version>7</version>
                        <defaultLibBundleDir>lib</defaultLibBundleDir>
                        <archive>
                            <manifestEntries>
                                <SCM-Revision>${buildNumber}</SCM-Revision>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencies>
       ...
    </dependencies>
</project>

I build the project with mvn clean package and looking inside the ear META-INF/MANIFEST.MF I get this:

Manifest-Version: 1.0
SCM-Revision: 
Archiver-Version: Plexus Archiver
Built-By: me
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_102

As you can see, the buildNumber property from the buildnumber-maven-plugin is empty. Any suggestion?

1
You need to execute the buildnumber-maven-plugin but you have defined it only in pluginManagement. So no binding to the life cycle has happend.khmarbaise
I have changed the app-ear/pom.xml including the buildnumber-maven-plugin. Nothing has changed in the MANIFEST.MFchess4ever
Please put the example project on github so I can take a look at it...khmarbaise
here it is github.com/chess4ever/maven-buildnumber-plugin, to run it you have to set the JAVA_HOME environment variablechess4ever

1 Answers

0
votes

Create a separate <plugins> tag </plugins> outside of <pluginManagement> and put the buildnumber maven plugin separately in there. That's what did it for me, don't ask why.