How to get git SHA1 value in Version-Version field in manifest for Maven project?

We use git and maven and logback.

This means that the stack trace in the log shows the version of the jar implementation that contains each line in the stack trace (see http://logback.qos.ch/reasonsToSwitch.html#packagingData for an example).

So, if we can pack the SHA1 of the current assembly into this field in the manifest of the artifact we are creating, it is very easy to find the exact source from git that generated the artifact containing this separate line in the source.

According to http://maven.apache.org/shared/maven-archiver/examples/manifestEntries.html the way to do this is to have the <key>value</key> in the maven-jar-plugin part of the pOM. This in my case means

 <Implementation-Version>FooBar</Implementation-Version> 

that leads to

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

Given that I can get SHA1 from https://github.com/koraktor/mavanagaiata , how can I install it correctly in the MANIFEST.MF file?

+6
source share
1 answer

Make sure that <Implementation-Version> is inside the <manifestEntries> element, not the <manifest> element.

Example:

  <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> 
+11
source

Source: https://habr.com/ru/post/906866/


All Articles