J Fabian Meier
J Fabian Meier

Reputation: 35795

Order of entries in MANIFEST.MF

I am adding entries to the MANIFEST.MF in Maven like

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
          <index>true</index>
          <manifest>
            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            <addBuildEnvironmentEntries>true</addBuildEnvironmentEntries>
          </manifest>
          <manifestSections>
            <manifestSection>
              <name>GAV</name>
              <manifestEntries>
                <GroupId>${project.groupId}</GroupId>
                <ArtifactId>${project.artifactId}</ArtifactId>
                <Version>${project.version}</Version>
                <Packaging>${project.packaging}</Packaging>
              </manifestEntries>
            </manifestSection>
            ...

The entries appear, but in arbitrary order. This does not matter for scripts which read them, but for humans which like to look up some things, the file looks messy. Is there a way to determine the order of the entries in the MANIFEST.MF?

Upvotes: 4

Views: 1127

Answers (2)

Milen Dyankov
Milen Dyankov

Reputation: 3052

You can not easily "determine the order of the entries in the MANIFEST.MF" in Maven. At least not simply by something like flipping a switch or configuration.

It can be done by a Maven plugin that generates the the MANIFEST.MF the way you want it and then instructs the maven-jar-plugin where to get it from. It's doable but not super easy. It also may break other plugins if they make assumptions about the MANIFEST.MF generation in Maven.

But if you only care about "humans which like to look up some things" then I suggest to have a look at bnd. It's a (dependency free, around 5Mb in size) library and command line tool that can do magic with JAR files.

Once you download it, you could use it to list the MANIFEST.MF in human friendly format by doing something like

→ bnd print ~/.m2/repository/org/apache/maven/maven-core/3.5.0/maven-core-3.5.0.jar

which IMHO gives you nicer view

[MANIFEST maven-core-3.5.0]
Archiver-Version                         Plexus Archiver
Build-Jdk                                1.7.0_80
Built-By                                 stephenc
Created-By                               Apache Maven 3.3.9
Implementation-Title                     Maven Core
Implementation-Vendor                    The Apache Software Foundation
Implementation-Vendor-Id                 org.apache.maven
Implementation-Version                   3.5.0
Manifest-Version                         1.0
Specification-Title                      Maven Core
Specification-Vendor                     The Apache Software Foundation
Specification-Version                    3.5.0

of what you call "messy" MANIFEST.MF :

→ unzip -q -c ~/.m2/repository/org/apache/maven/maven-core/3.5.0/maven-core-3.5.0.jar META-INF/MANIFEST.MF
Manifest-Version: 1.0
Implementation-Vendor: The Apache Software Foundation
Implementation-Title: Maven Core
Implementation-Version: 3.5.0
Implementation-Vendor-Id: org.apache.maven
Built-By: stephenc
Build-Jdk: 1.7.0_80
Specification-Vendor: The Apache Software Foundation
Specification-Title: Maven Core
Created-By: Apache Maven 3.3.9
Specification-Version: 3.5.0
Archiver-Version: Plexus Archiver

Have a look at the documentation of the "print" command for more options.

Upvotes: 1

grindlewald
grindlewald

Reputation: 338

I don't think that's possible, as Manifest internally works with Map entries. And, oracle documentation mentions that ordering is not significant in Manifest. I suppose they use HashMap. Perhaps if Manifest is extended to use LinkedHashMap, the order might be preserved. I found this http://juneau.apache.org/site/apidocs-7.2.2/org/apache/juneau/utils/ManifestFile.html

Upvotes: 4

Related Questions