简短版本:我想将当前模块及其依赖项的最新修订号(与单个模块相关)存储在 jar 的清单中。
我有一个多模块 Maven 项目。这些模块被内置到有阴影的 jar 中(包括所有依赖项),因此它们可以独立部署。一些模块依赖于其他模块(首先构建的几个模块是其他模块的“公用”)。在构建这些模块时,我想包含模块的最新提交修订版和依赖项最新提交修订版。我的模块都保存在同一个 git-repo 中(没有“sub-gits”)。
例子:
<module>common</module>
<module>data</module>
<module>application1</module>
前两个模块是公共模块,它们是application1
.
假设最新的提交是 864ccc,我在其中对 Data 和application1
. Common
但是最后一次更改是在提交 889a01 中。在构建这些模块时,我希望清单中有以下输出:
Revision-App: 864ccc
Revision-Common: 889a01
Revision-Data: 864ccc
我以前使用过 MojoHaus 的buildnumber-maven-plugin和 SVN。通过这个设置,我可以在 pom.xml 中使用以下内容来完成此操作:
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<URL>${project.url}</URL>
<Application-Build-Time>${timeStamp}</Application-Build-Time>
<Revision-Appl>${app.rev}</Revision-Application>
<Revision-Data>${data.rev}</Revision-Data>
<Revision-Common>${common.rev}</Revision-Common>
</manifestEntries>
</archive>
<outputDirectory>../target</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>${buildnumber-maven-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<version>1.8.5</version>
</dependency>
</dependencies>
<configuration>
<providerImplementations>
<svn>javasvn</svn>
</providerImplementations>
</configuration>
<executions>
<execution>
<id>timeStamp</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<buildNumberPropertyName>timeStamp</buildNumberPropertyName>
<format>{0,date,yyyy-MM-dd HH:mm:ss}</format>
<items>
<item>timestamp</item>
</items>
<revisionOnScmFailure>SVN_FAILURE</revisionOnScmFailure>
</configuration>
</execution>
<execution>
<id>appRev</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<buildNumberPropertyName>app.rev</buildNumberPropertyName>
<useLastCommittedRevision>true</useLastCommittedRevision>
<scmDirectory>${project.basedir}</scmDirectory>
</configuration>
</execution>
<execution>
<id>commonRev</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<buildNumberPropertyName>common.rev</buildNumberPropertyName>
<useLastCommittedRevision>true</useLastCommittedRevision>
<scmDirectory>${project.basedir}/../common</scmDirectory>
<getRevisionOnlyOnce>false</getRevisionOnlyOnce>
<revisionOnScmFailure>SVN_FAILURE</revisionOnScmFailure>
</configuration>
</execution>
<execution>
<id>dataRev</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<buildNumberPropertyName>data.rev</buildNumberPropertyName>
<useLastCommittedRevision>true</useLastCommittedRevision>
<scmDirectory>${project.basedir}/../data</scmDirectory>
<getRevisionOnlyOnce>false</getRevisionOnlyOnce>
<revisionOnScmFailure>SVN_FAILURE</revisionOnScmFailure>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<artifactSet>
<includes>
<include>com.company.package:*</include>
</includes>
</artifactSet>
<createDependencyReducedPom>true</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
但我一生都无法弄清楚如何用 git 做同样的事情。我只能获得超级 pom 的 HEAD 修订版(包含模块)。
你能帮我用 git 得到同样的结果吗?
运行 mvn build 给我以下输出:
[INFO] --- buildnumber-maven-plugin:1.4:create (appRev) @ common ---
[INFO] Executing: /bin/sh -c cd '/home/user/java/application1' && 'git' 'rev-parse' '--verify' 'HEAD'
[INFO] Working directory: /home/user/java/application1
[INFO] Storing buildNumber: 864cccf9056d273313eb9fb690b58674f72d4a6b at timestamp: 1539006765309
[INFO] Storing buildScmBranch: mvn-revision
[INFO]
[INFO] --- buildnumber-maven-plugin:1.4:create (commonRev) @ common ---
[INFO] Executing: /bin/sh -c cd '/home/user/java/common/../common' && 'git' 'rev-parse' '--verify' 'HEAD'
[INFO] Working directory: /home/user/java/common/../common
[INFO] Storing buildNumber: 864cccf9056d273313eb9fb690b58674f72d4a6b at timestamp: 1539006765326
[INFO] Storing buildScmBranch: mvn-revision
[INFO]
[INFO] --- buildnumber-maven-plugin:1.4:create (dataRev) @ common ---
[INFO] Executing: /bin/sh -c cd '/home/user/java/common/../data' && 'git' 'rev-parse' '--verify' 'HEAD'
[INFO] Working directory: /home/user/java/common/../data
[INFO] Storing buildNumber: 864cccf9056d273313eb9fb690b58674f72d4a6b at timestamp: 1539006765330
[INFO] Storing buildScmBranch: mvn-revision
[INFO]
我知道跑步git rev-parse --verify HEAD
会给我那个输出。但我想让第一行的输出git rev-list --verify HEAD -- .
在当前工作目录中运行。
你有什么想法?
我不需要坚持使用这个插件,我只想要描述的结果。