2010-06-06 75 views
5

我们的项目有一个很好的黑客(虽然我猜有更好的方法来做到这一点),以将修订信息嵌入到工件(jar等),当我们使用svn。如何嵌入版本信息使用mercurial和maven(和svn)

现在我们已经迁移到了mercurial,并且我们想要一个类似的东西,但是在我开始使用mercurial进行类似的攻击之前,我想知道是否有更好的方法来做到这一点。

感谢您的回答!

<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> 

回答

4

Maven Build Number Plugin具有自1.0-β-4水银支持(见MOJO-1432)。目标buildnumber:hgchangeset设置了两个项目属性,其中包含可用于筛选以获得等效结果的更改集标识和更改集日期。

2

听起来像帕斯卡尔有官方的maven方式做到这一点,但如果这样做最终会模仿你的svn黑客,在善变的最好的相应命令是:

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

,或者如果你正在使用的标签并想要看中:

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

请参阅hg help templates的所有选项。

+0

'hg parent'而不是'hg log -r .'怎么样? – Alex 2014-11-28 17:55:02