Adding custom fields to build.properties generated by buildnumber-maven-plugin

1k Views Asked by At

I am using the buildnumber-maven-plugin to include various version parameters in my WAR artifact to be visible on the page. In my pom.xml:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    <version>1.4</version>
    <executions>
      <execution>
        <id>create-buildmeta</id>
        <phase>prepare-package</phase>
        <goals>
          <goal>create-metadata</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <doCheck>false</doCheck>
      <doUpdate>false</doUpdate>
      <outputDirectory>${project.build.directory}/${project.build.finalName}</outputDirectory>
    </configuration>
</plugin>

That produces a build.properties that looks something like:

#Created by build system. Do not modify
#Fri Jan 05 17:10:02 EST 2018
version=2.1.0-SNAPSHOT
revision=1234
name=myApp
timestamp=1515190202388

I would like to include some more fields from my svn info in the file, like the last user who made a change to the branch etc. Is there a way to configure that and how?

1

There are 1 best solutions below

2
On

Unfortunately, this is not easily possible with buildnumber-maven-plugin As you can see from the source code, only the four properties you already mentioned are generated by default:

version=2.1.0-SNAPSHOT
revision=1234
name=myApp
timestamp=1515190202388

The only way I could imagine to achieve your goal using buildnumber-maven-plugin is to execute svn and store the information needed in a property (in the example last.changed.user), which you can insert into the configuration as below

<configuration>
    <doCheck>false</doCheck>
    <doUpdate>false</doUpdate>
    <outputDirectory>${project.build.directory}/${project.build.finalName}</outputDirectory>
    <properties>
        <user>${last.changed.user}</user>
    </properties>
</configuration>

This produces an additional property, giving a result like this:

version=2.1.0-SNAPSHOT
revision=1234
name=myApp
user=someUser
timestamp=1515190202388

Unfortunately, I don't know enough about maven's svn integration to give you an example how to store the information you need in an property.