views:

78

answers:

2

Our project had a nice hack (although I'm guessing there are better ways to do it) to embed revision information into the artifacts (jar etc.) when we used svn.

Now we have migrated to mercurial, and we want to have a similar thing, but before I start working on a similar hack with mercurial, I wanted to know if there are better ways to do this.

Thanks for your answers!

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
            <execution>
                    <phase>process-classes</phase>
                    <id>svninfo</id>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                <configuration>
                    <executable>svn</executable>
                    <arguments>
                    <argument>info</argument>
                    <argument>../</argument>
                    <argument>></argument>
                    <argument>target/some-project/META-INF/svninfo.txt</argument>
                    </arguments>
                </configuration>
            </execution>
        </executions>
    </plugin>
+1  A: 

The Maven Build Number Plugin has support for Mercurial since 1.0-beta-4 (see MOJO-1432). The buildnumber:hgchangeset goal sets two project properties with the changeset id and changeset date that you could use with filtering to obtain an equivalent result.

Pascal Thivent
+1  A: 

Sounds like Pascal has the official maven way to do it, but if you do end up emulating your svn hack, the best corresponding command in mercurial would be:

hg log -r . --template '{node|short}\n'

or if you're using tags and want to get fancy:

hg log -r . --template '{latesttag}+{latestance}\n'

see hg help templates for all the options.

Ry4an