mavenmercurialversioningbuildnumber-maven-plugin

Inject the Mercurial working directory changeset id such as (838cb9c0367e) into properties file via Maven?


We use Maven for our builds and Mercurial for our changesets. While our software has a major version handled already we would really like to be able to know what Mercurial changeset was used to build any server that runs our software.

Does anybody know of a way in Maven to grab the working directory's changeset in Mercurial and get it into a properties file or something so we can then display it somewhere in our application when sys admins do a "sanity check" against what version is currently running?


Solution

  • Merge this to your pom.xml:

    <project>
      <build>
        <resources>
          <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
          </resource>
        </resources>
    
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <executions>
              <execution>
                <phase>validate</phase>
                <goals>
                  <goal>hgchangeset</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </project>
    

    Then make a .properties file in src/main/resources with a property set as ${changeSet}. For example:

    revision = ${changeSet}
    modificationTime = ${changeSetDate}