2

Found this question about adding a version to manifest.mf: How do I add an Implementation-Version value to a jar manifest using Maven?, but how to add them when using shade plugin?

I tried with the maven-shade-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <finalName>ispf-win</finalName>
                <shadedArtifactAttached>shade</shadedArtifactAttached>
                <outputDirectory>${project.build.directory}/ispf-win</outputDirectory>
                <transformers>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>desktop.win.main.Main</mainClass>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
</plugin>

However, that generated an error:

Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.2.4:shade (default) on project desktop.win:
Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:3.2.4:shade for parameter addDefaultImplementationEntries: 
Cannot find 'addDefaultImplementationEntries' in class java.util.jar.Manifest
cb4
  • 6,689
  • 7
  • 45
  • 57
Wortig
  • 963
  • 2
  • 11
  • 37

2 Answers2

2

With these standard maven properties set:

<name>Project Name</name>
<organization.name>Company</organization.name>
<groupId>Group ID</groupId>
<version>1.0.0</version>

And the following maven shade configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <transformers>
                    <!-- Add entries to the manifest. -->
                    <transformer implementation = "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <manifestEntries>
                            <Implementation-Title>${project.name}</Implementation-Title>
                            <Implementation-Version>${project.version}</Implementation-Version>
                            <Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id>
                            <Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
                        </manifestEntries>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
</plugin>

You will get the desired result:

Manifest-Version: 1.0
Created-By: Maven Jar Plugin 3.2.0
Build-Jdk-Spec: 11
Implementation-Title: Project Name
Implementation-Vendor: Company
Implementation-Vendor-Id: Group ID
Implementation-Version: 1.0.0

For a "set it and forget it" configuration in a multi-module project, set <organization.name> in the parent pom <properties> section and <name> in each module pom.

cb4
  • 6,689
  • 7
  • 45
  • 57
  • Well done. But since there was no further input from @Wortig on this question, over a month old, it just *could* be possible that my post was quite adequate. – g00se Aug 10 '22 at 15:55
  • 1
    @g00se Others would have downvoted you but I like being helpful. Thank you for answering! I *did* credit that it worked, but your answer is low quality by SO standards. If it was enough for Wortig, then win-win. Didn't help me on a project that required shade's precise control over final jar contents. And others will be in in the same boat, though it could be 1, 5, even 10 years from now. How frustrating if their only answer is a stale link? Makes for a poor SO experience that now won't happen. (Bonus for me: when I forget what I did, the exact answer will be right here:-) – cb4 Aug 10 '22 at 18:54
1

I think you should maybe rather be using <manifestEntries> See this example: THIS

cb4
  • 6,689
  • 7
  • 45
  • 57
g00se
  • 3,207
  • 2
  • 5
  • 9
  • 1
    Please review [How to write a good answer](https://stackoverflow.com/help/how-to-answer) - it should include more than just a link. And although your solution gets the job done, it does not answer the OP's question because it does not generate a manifest with maven-shade. – cb4 Aug 10 '22 at 13:52