When a project uses the Maven-jar-plugin, it's easy to include a custom manifest file in the jar, but I can't find a way to do the same thing with Maven shade. How can I use my own manifest file while using the "Maven-shade-plugin"?
Additional details:
My custom manifest file is located in "src/main/resources/META-INF/MANIFEST.MF". Maven is not including my file, instead it is being replaced in the final jar with a default Maven manifest file.
The reason I need a custom manifest file is to specify some JavaBeans classes in my manifest, for a swing component library. Multiple JavaBeans classes should be specified in the manifest file in the following format, as described here. Note that the empty lines (and the line grouping) are important for marking JavaBeans classes in the manifest.
Name: SomeBean1.class
Java-Bean: True
Name: SomeBean2.class
Java-Bean: True
Name: SomeBean3.class
Java-Bean: True
A list of attempted solutions (these did not work):
This code only works when using the Maven jar plugin (not shade).
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile> </archive> </configuration> </plugin>
This link says "As with all the examples here, this configuration can be used in all plugins that use Maven Archiver, not just Maven-jar-plugin as in this example." Based on that advice, I tried the following code, but this did not work either. (Maven still replaced my manifest file with the default manifest file.)
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.3</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <archive> <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile> </archive> <shadedArtifactAttached>true</shadedArtifactAttached> <shadedClassifierName>core</shadedClassifierName> <createDependencyReducedPom>false</createDependencyReducedPom> <minimizeJar>true</minimizeJar> </configuration> </execution> </executions> </plugin>
I cannot use the shade "ManifestResourceTransformer" as described here to do the job, for the following reason. I need to add JavaBeans classes to my manifest file as described above under "additional details". However, if I add manifest entries using the shade ManifestResourceTransformer, those entries are inserted into the manifest file in an unpredictable (random-seeming) ordering. For specifying JavaBeans classes, the ordering of the manifest entries (the line order) is important.
I attempted to use IncludeResourceTransformer, but the below code produces the following error: "Error creating shaded jar: duplicate entry: META-INF/MANIFEST.MF".
<configuration> <shadedArtifactAttached>true</shadedArtifactAttached> <shadedClassifierName>core</shadedClassifierName><createDependencyReducedPom>false</createDependencyReducedPom> <minimizeJar>true</minimizeJar> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> <resource>META-INF/MANIFEST.MF</resource> <file>src/main/resources/META-INF/MANIFEST.MF</file> </transformer> </transformers> </configuration>