我们使用 git 和 maven 以及 logback。
这意味着日志中的堆栈跟踪显示包含堆栈跟踪中每一行的 jar 的实现版本(有关示例,请参见 http://logback.qos.ch/reasonsToSwitch.html#packagingData)。
因此,如果我们可以将当前构建的 SHA1 打包到正在构建的 Artifact 的 list 中的那个字段中,就可以很容易地从 git 中找到确切的源,该源生成了包含源中单独一行的 Artifact 。
根据 http://maven.apache.org/shared/maven-archiver/examples/manifestEntries.html这样做的方法是有一个 <key>value</key>
pom 的 maven-jar-plugin 部分中的行。在我的例子中,这意味着
<Implementation-Version>FooBar</Implementation-Version>
结果是
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3:jar (default-jar) on project axsFTP: Unable to parse configuration of mojo org.apache.maven.plugins:maven-jar-plugin:2.3:ja
r for parameter manifest: Cannot find setter, adder nor field in org.apache.maven.archiver.ManifestConfiguration for 'implementationVersion' -> [Help 1]
鉴于我可以从 https://github.com/koraktor/mavanagaiata 获得 SHA1如何在 MANIFEST.MF 文件中正确设置它?
最佳答案
检查 <Implementation-Version>
在<manifestEntries>
里面元素,而不是 <manifest>
元素。
例子:
<build>
<plugins>
<plugin>
<groupId>com.github.koraktor</groupId>
<artifactId>mavanagaiata</artifactId>
<version>0.3.1</version>
<executions>
<execution>
<id>git-commit</id>
<phase>validate</phase>
<goals>
<goal>commit</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<archive>
<manifestEntries>
<Implementation-Version>${mvngit.commit.id}</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
关于java - 如何获取 Maven 项目 list 中 Implementation-Version 字段中的 git SHA1 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9004575/