Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed revision information using mercurial and maven (and svn)

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>
like image 600
Enno Shioji Avatar asked Jun 06 '10 13:06

Enno Shioji


2 Answers

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.

like image 196
Pascal Thivent Avatar answered Oct 27 '22 00:10

Pascal Thivent


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.

like image 32
Ry4an Brase Avatar answered Oct 26 '22 22:10

Ry4an Brase