added a comment - - edited
After some tracking, maven-jar-plugin depends on maven-archiver, which uses plexus-archiver internally to build archives. I found the following lines in plexus-archiver:JarArchiver.java:createManifest:
JdkManifestFactory.merge( finalManifest, filesetManifest, false );
JdkManifestFactory.merge( finalManifest, configuredManifest, false );
JdkManifestFactory.merge( finalManifest, manifest, !mergeManifestsMain );
These lines seem the responsible for the issue in hand, however, there is a comment prceeding this block which declares that "Precedence: manifestFile wins over inline manifest, over manifests read from the filesets over the original manifest.". Which is a bit strange, why would a supplied file have more precedence than supplied configuration ?)
To cut a long debugging story shorter on anyone who intends to dig through this, here are some facts:
- The original MANIFEST file is represented by the variable manifest in the above code
- Any additional parameters supplied through manifestEntries entry in the POM, is set at configuredManifest (This happens by maven-archiver:MavenArchiver.java:createArchive)
- The POM's XML configuration (manifestEntries and manifestFile) are binded by the maven-jar-plugin to an object of MavenArchiveConfiguration, this config object is supplied "as is" to the previously mentioned maven-archiver:MavenArchiver.java:createArchive method.
I was successfully able to reach the desired results by a small change in maven-archiver shown in the following patch:
hesham@hesham-work-laptop ~/dev/maven $ cat diff-maven-archiver
--- src/main/java/org/apache/maven/archiver/MavenArchiver.java (revision 1458914)
+++ src/main/java/org/apache/maven/archiver/MavenArchiver.java (working copy)
@@ -20,6 +20,7 @@
@@ -546,7 +547,7 @@
if ( manifestFile != null )
- archiver.setManifest( manifestFile );
+ archiver.addConfiguredManifest(new Manifest(new FileReader(manifestFile)));
Manifest manifest = getManifest( session, workingProject, archiveConfiguration );
However, considering I am new to the code base I feel this is a bit hackish, I will try to dig more into things to figure out more formal way.
BTW, a small issue brings itself: MANIFEST's Bundle-Version should conform to the OSGi specs, this will need manipulating the version declared in the POM to be compatible with OSGi's MANIFEST. (i.e. POM's 1.0.0-RC1-SNAPSHOT would turn something like 1.0.0.RC1-SNAPSHOT).