0

I'm trying to add branch and build information to my war's manifest and while the keys show up on the manifest, the values are null. The values I'm pulling from the buildnumber-maven-plugin, and when this plugin executes the log shows the values. I also added a maven-antrun-plugin task to echo the values I'm passing into the war plugin, and they display in the log as well. So I'm having trouble finding out why they are null when writing to the manifest. Here's some examples:

Here's my buildnumber plugin:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.4</version>
            <configuration>
                <doCheck>false</doCheck>
                <doUpdate>false</doUpdate>
            </configuration>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>create</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

When this plugin executes I see in the logs..

[INFO] --- buildnumber-maven-plugin:1.4:create (default) @ my-project ---
[INFO] Executing: cmd.exe /X /C "git rev-parse --verify HEAD"
[INFO] Working directory: C:\workspace\my-project
[INFO] Storing buildNumber: 09w3e456df44cd81a5d20f4502f957ae80d52eb2 at timestamp: 1455818030872
[INFO] Storing buildScmBranch: master

Next I just added in a ant task to output these values as well..

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <phase>generate-resources</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <echo>buildNumber: ${buildNumber}</echo>
                    <echo>scmBranch: ${scmBranch}</echo>
                </tasks>
            </configuration>
        </execution>
    </executions>
  </plugin>

And in the logs I see...

[INFO] --- maven-antrun-plugin:1.8:run (default) @ my-project ---
[WARNING] Parameter tasks is deprecated, use target instead
[INFO] Executing tasks

main:
 [echo] buildNumber: 09w3e456df44cd81a5d20f4502f957ae80d52eb2 
 [echo] scmBranch: master

And lastly with the war plugin/archiver, here's where the issue is... Here's the plugin..

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <archive>
                    <manifest>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                    </manifest>
                    <manifestEntries>
                        <sha>${buildNumber}</sha>
                        <branch>${scmBranch}</branch>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>

And here's the resulting manifest where the branch and sha are coming out blank..

Manifest-Version: 1.0
Implementation-Vendor: My Company
sha: 
Implementation-Title: My Project
Implementation-Version: 0.0.1-SNAPSHOT
Implementation-Vendor-Id: com.myproject
Build-Jdk: 1.7.0_79
Built-By: me
branch:
Created-By: Maven Integration for Eclipse
Implementation-URL: [purposely omitted] 

You see that branch and sha are both blank, but in the logs above those values are obviously available. Is something wiping these values out or is there something further required to bubble these values up into the archiver within the maven war plugin?

byte-crunch
  • 271
  • 2
  • 13
  • That is certainly bizarre. Did you ran `mvn clean package`? Can you try with `$\{buildNumber}` (it's weird [but the docs mention that](http://www.mojohaus.org/buildnumber-maven-plugin/usage.html))? – Tunaki Feb 18 '16 at 18:38
  • Yeah I tried the $\{buildNumber}, but with that, the manifest takes that value literally ie: ( sha: $\{buildNumber} ) is literally what i see on the manifest. – byte-crunch Feb 18 '16 at 18:48
  • (I think the doc is wrong yeah). But I just made a simple test and I can't reproduce your behaviour. – Tunaki Feb 18 '16 at 18:50
  • Yeah that's odd, I also tried the clean package, but it's generating the same result. – byte-crunch Feb 18 '16 at 18:55
  • Where have you defined the buildnumber-maven-plugin? Did you have defined in the pluginManagement area? – khmarbaise Feb 19 '16 at 08:09
  • Hello, actually yes I have the buildnumber plugin defined in pluginManagement in a parent pom, the child pom defines basically what i have above in the same pom as the maven war plugin. – byte-crunch Feb 19 '16 at 17:35
  • i'm basically using the pluginManagement to define the version of buildnumber plugin, but its actual use and config is within the build / plugins section. – byte-crunch Feb 19 '16 at 17:39

0 Answers0