【问题标题】:How to embed revision information using mercurial and maven (and svn)如何使用 mercurial 和 maven(和 svn)嵌入修订信息
【发布时间】:2025-12-10 12:25:02
【问题描述】:

当我们使用 svn 时,我们的项目有一个很好的 hack(虽然我猜有更好的方法)来将修订信息嵌入到工件(jar 等)中。

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

感谢您的回答!

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

【问题讨论】:

    标签: java svn maven-2 mercurial release-management


    【解决方案1】:

    Maven Build Number Plugin 从 1.0-beta-4 开始支持 Mercurial(请参阅 MOJO-1432)。 buildnumber:hgchangeset 目标设置了两个项目属性,其中包含变更集 id 和变更集日期,您可以使用它们进行过滤以获得等效结果。

    【讨论】:

      【解决方案2】:

      听起来 Pascal 有官方的 maven 方法,但如果你最终模拟了你的 svn hack,那么在 mercurial 中最好的对应命令是:

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

      或者如果你正在使用标签并且想要花哨:

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

      请参阅hg help templates 了解所有选项。

      【讨论】:

      • hg parent 代替hg log -r . 怎么样?
      最近更新 更多