【问题标题】:How to get the git SHA1 value in the Implementation-Version field in the manifest for a Maven project?如何在 Maven 项目的清单中的 Implementation-Version 字段中获取 git SHA1 值?
【发布时间】:2012-02-18 17:55:40
【问题描述】:

我们使用 git、maven 和 logback。

这意味着日志中的堆栈跟踪显示了包含堆栈跟踪中每一行的 jar 的实现版本(参见http://logback.qos.ch/reasonsToSwitch.html#packagingData 示例)。

因此,如果我们可以将当前构建的 SHA1 打包到正在构建的工件清单中的该字段中,则很容易从 git 中找到确切的源,该源生成包含源中该单独行的工件。

根据http://maven.apache.org/shared/maven-archiver/examples/manifestEntries.html,这样做的方法是在 pom 的 maven-jar-plugin 部分中有一个 <key>value</key> 行。在我的情况下,这意味着

<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 文件中正确设置?

【问题讨论】:

    标签: java git maven logback mavanagaiata


    【解决方案1】:

    检查&lt;Implementation-Version&gt; 是否在&lt;manifestEntries&gt; 元素内,而不是&lt;manifest&gt; 元素内。

    例子:

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

    【讨论】:

    • 好的,这行得通。以为我也测试了这些,哦,好吧。谢谢。
    • Die Versiosnummer von mavanagaiata ist mittlerweile 0.7.2。 Dies hat einige kleinere Probleme bei mir beseitigt(git-Archiv finden 等)
    • 截至 2018 年,我在另一个项目中使用了 pl.project13.maven:git-commit-id-plugin,效果很好。设置属性和编写属性文件。
    猜你喜欢
    • 2010-10-29
    • 2010-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    • 2021-04-30
    • 2012-08-24
    • 1970-01-01
    相关资源
    最近更新 更多