2

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

Akshay Hazari
  • 3,186
  • 4
  • 48
  • 84
  • Using somewhere the maven-shade-plugin? – khmarbaise Feb 24 '21 at 16:13
  • @khmarbaise Yes I have it in multiple pom.xml – Akshay Hazari Feb 24 '21 at 16:14
  • So you are using maven-shade-plugin which is the source of the problem.. the question is this really problem..because it's on DEBUG level... ? – khmarbaise Feb 24 '21 at 16:44
  • @khmarbaise I just saw where it was taking more time during the build and then checked these logs which would not show without debug. I am checking on this as you mentioned `maven-shade-plugin` - https://stackoverflow.com/questions/11314182/maven-shade-plugin-adding-dependency-reduced-pom-xml-to-base-directory What could I check more to find where is the problem? – Akshay Hazari Feb 24 '21 at 16:45
  • Check this recipe https://stackoverflow.com/a/38257466/2700344 – leftjoin Feb 25 '21 at 17:30

1 Answers1

1

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>
leftjoin
  • 36,950
  • 8
  • 57
  • 116