javamavenjarmanifest.mfmaven-jar-plugin

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?


Solution

  • 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