通过Maven将Mercurial工作目录更改集ID(例如(838cb9c0367e)注入属性文件吗?

问题描述 投票:6回答:5

我们使用Maven进行构建,使用Mercurial进行变更集。尽管我们的软件已经处理了主要版本,但我们真的很想知道Mercurial变更集是用来构建任何运行我们软件的服务器的。

没有人知道Maven中如何在Mercurial中获取工作目录的变更集并将其保存到属性文件或其他内容中的方法,以便当系统管理员针对版本是什么进行“合理性检查”时,我们可以将其显示在应用程序中的某个位置。当前正在运行?

maven mercurial versioning buildnumber-maven-plugin
5个回答
6
投票

将此合并到您的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>

然后在.properties中创建一个src/main/resources文件,并将属性设置为${changeSet}。例如:

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

6
投票

您可以制作一个更新挂钩,将变更集ID输出到未版本化的.properties文件中:

[hooks]
update = echo changesetid=$HG_PARENT1 > version.properties

此方法的优点是,您可以根据需要轻松地自定义此值,并且该构建独立于版本控制系统(或缺少版本控制系统)。

[如果您想在生成它的Maven构建中放一些东西,您是否看过Buildnumber Maven Pluginhgchangeset目标)或Maven Mercurial Build Number Plugin


0
投票

如果您可以拦截命令输出(进入环境变量,例如),hg id -i将是简单的方法。可以使用hg log --template "..." tip

构造更复杂的ID

0
投票

您可以使用Maven的antrun插件运行<exec><java>任务,该任务将生成包含该信息的属性文件。不过,这不是很优雅。


0
投票

如果需要更多的属性,还可以使用https://github.com/volodya-lombrozo/hg-revision-plugin,而不是org.codehaus.mojo.buildnumber-maven-plugin。

 <build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <groupId>com.github.volodya-lombrozo</groupId>
            <artifactId>hg-revision-plugin</artifactId>
            <version>0.2</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>
                            scan
                        </goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

然后您可以使用第二个属性:

hg.author=${hg.author}
hg.branch=${hg.branch}
hg.revision=${hg.rev}
hg.node=${hg.node}
hg.tags=${hg.tags}
hg.desc=${hg.desc}
hg.date=${hg.date}
© www.soinside.com 2019 - 2024. All rights reserved.