如何在Maven项目的清单中的Implementation-Version字段中获取git SHA1值?

Tho*_*sen 7 java git logback maven mavanagaiata

我们使用git和maven以及logback.

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

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

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

<Implementation-Version>FooBar</Implementation-Version>
Run Code Online (Sandbox Code Playgroud)

结果

[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]
Run Code Online (Sandbox Code Playgroud)

鉴于我可以从https://github.com/koraktor/mavanagaiata获取SHA1,如何在MANIFEST.MF文件中正确设置?

Mar*_*lis 12

检查它<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>
Run Code Online (Sandbox Code Playgroud)