How to generate MANIFEST.MF file during compile phase
Asked Answered
M

2

12

Standard way - using maven-jar-plugin - generates manifest file only during package phase and directly into jar file.

What I need is to generate manifest during compile phase and to be available in <target>/classes/META-INF.

My goal is to be able to read this manifest file in project running in debug mode in IntelliJ Idea. (Idea resolves in-project jar dependencies from <target>/classes instead of from <target>/*.jar - for hot-swap purpose).

The only solution I know of so far is to actually create my own MANIFEST.MF in src/main/java/resources/META-INF and let it be filtered+copied during resources phase. But I want to avoid this solution, I want the manifest to be generated standard way using <archive> configuration in pom file.

Mcgann answered 8/1, 2016 at 9:54 Comment(4)
I don't think there is a plugin to do that directly. A contrived way would be to bind an execution of maven-jar-plugin to compile, unpack the jar and copy the MANIFEST... A more direct solution would be to create a custom plugin using Maven Archiver.Interconnect
Hi Petr, did you find a solution for this?Hildegardhildegarde
@Hildegardhildegarde this is kinda old question and I have forgotten about it :) Have you tried the @frekele's answer below? If it does not work I could make a proposition / push request to maven-jar-plugin on github, if the project is there and the repo owner is active. Or make a custom plugin as @Interconnect suggests.Declension
I've tried @frekele's answer and it didn't generate target/Project-version/META-INF/MANIFEST.MF as needed to try debugging a project in Netbeans where it runs from that location instead of from the WAR file. I'm looking for an option to create the manifest there during build instead of in .war during package.Laural
I
4

You can do this with maven-bundle-plugin.

   <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>3.3.0</version>
        <executions>
            <execution>
                <id>bundle-manifest</id>
                <phase>process-classes</phase>
                <goals>
                    <goal>manifest</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <archive>
                <index>true</index>
                <manifest>
                    <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                </manifest>
                <manifestEntries>
                    <Implementation-URL>${project.url}</Implementation-URL>
                    <Java-Version>${java.version}</Java-Version>
                    <Java-Vendor>${java.vendor}</Java-Vendor>
                    <Os-Name>${os.name}</Os-Name>
                    <Os-Arch>${os.arch}</Os-Arch>
                    <Os-Version>${os.version}</Os-Version>
                    <Scm-Url>${project.scm.url}</Scm-Url>
                    <Scm-Connection>${project.scm.connection}</Scm-Connection>
                </manifestEntries>
            </archive>
        </configuration>
    </plugin>
Incorporable answered 30/3, 2017 at 22:6 Comment(1)
This isn't generating a MANIFEST.MF in target/Project-version/META-INF/ like a similar archive/manifestEntries block in maven-war-plugin is doing during package to target/Project-verssion.warLaural
U
0

Many thanks for the excellent answer from @frekele. As I cannot add comments to existing answers, so adding this one to note that you need to tie to the compile phase instead of process-classes if you want to generate the manifest during the compile phase:

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>4.2.1</version>
    <executions>
        <execution>
        <id>bundle-manifest</id>
        <phase>compile</phase>
        <!-- ... -->
Unofficial answered 31/5, 2020 at 23:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.