Maven Build getting stuck for long and debug logs showing [DEBUG] We have a duplicate META-INF/MANIFEST.MF

Viewed 317

Maven build is getting stuck and has been running for a long time

I see several lines similar to the following in logs for different packages in debug mode after mvn clean install -X

[DEBUG] We have a duplicate META-INF/NOTICE.txt in /Users/kimjongun/.m2/repository/commons-cli/commons-cli/1.4/commons-cli-1.4.jar

Not sure how to resolve this, couldn't find much help on the net, and I am fairly new to Java.

Any help is appreciated

1 Answers

In this post it is already explained how to use your MANIFEST and exclude some other MANIFEST files: https://stackoverflow.com/a/38257466/2700344 I just want to add why you may need your own manifest file You are building new jar with executable class and this what your need MANIFEST.MF for - to Define the entry point of the Application, make the Jar executable and add dependency classpath. This is why you may need your own manifest. You can use maven-jar-plugin for configuring main class like this and it will create manifest for you:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <configuration>
      <archive>
        <manifest>
        <mainClass>com.AkshayHasari.App</mainClass>
        </manifest>
      </archive>
    </configuration>
</plugin>

Also You can simply exclude MANIFEST files and some other files in the shade plugin configuration using filter:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>

                    <!-- filters section excludes some stuff from the target JAR that
                        oughtn't be in there - such as JAR metadata, ant build files, text files,
                        etc. that are packaged with some dependencies, but which don't belong in
                        an uber JAR. -->
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*</exclude>
                                <exclude>NOTICE</exclude>
                                <exclude>/*.txt</exclude>
                                <exclude>build.properties</exclude>
                            </excludes>
                        </filter>
                    </filters>
                    <!-- <finalName>${project.artifactId}-${project.version}-shaded</finalName> -->
                    <outputDirectory>${basedir}/target</outputDirectory>
                </configuration>
            </execution>
        </executions>
    </plugin>
Related