Search code examples
mavenmanifest.mfmaven-jar-plugin

Build JAR with custom manifest in maven


I am trying to get maven to create the artifact jar with a custom MANIFEST.MF.

Sounds like an easy task using the following snippet:

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifestFile>${project.build.directory}/META-INF/MANIFEST.MF</manifestFile>
        </archive>
    </configuration>
</plugin>

Problem is, that the maven-jar-plugin still "messes" with the manifest I created manually. The documentation states

The content of your own manifest file will be merged with the entries created by Maven Archiver

Unfortunately this is not the case for the Manifest-Version. It will always be set to "1.0". (I know that in theory this is correct, but for reasons I cannot influence, I need a different value in there). Any ideas on how to step the jar plugin from touching my manifest at all or at least keeping its hands of the Manifest-Version?


Solution

  • I finally managed to solve my problem using the maven-antrun-plugin:

    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
            <execution>
                <phase>package</phase>
                <configuration>
                    <target>
                        <jar file="${project.build.directory}/${project.build.finalName}.jar" update="true" manifest="${project.build.directory}/META-INF/MANIFEST.MF" />
                    </target>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
            </execution>
        </executions>
    </plugin>