Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

We use git and maven and logback.

This mean that the stack traces in the log show the Implementation-Version of the jar containing each line in the stack trace (see http://logback.qos.ch/reasonsToSwitch.html#packagingData for an example).

So if we can package the SHA1 of the current build into that field in the manifest of the artifact being built, it is very easy to locate the exact source from git that generated the artifact containing that individual line in the source.

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

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

which results in

[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 the SHA1 from https://github.com/koraktor/mavanagaiata how do I get this correctly set in the MANIFEST.MF file?

like image 847
Thorbjørn Ravn Andersen Avatar asked Jan 25 '12 14:01

Thorbjørn Ravn Andersen


1 Answers

Check that the <Implementation-Version> is inside a <manifestEntries> element, and not a <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>
like image 63
Martin Ellis Avatar answered Oct 16 '22 21:10

Martin Ellis