For

  <dependencies>
    ...
    <dependency>
        <groupId>com.manuel.jordan</groupId>
        <artifactId>some module</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    ... 
  </dependencies>

  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.4</version>
            <executions>
                <execution>
                    <id>create-fat-jar</id>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <finalName>somename</finalName>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>

The plugin works well, but always appears this message:

[WARNING] moduleA-0.0.1-SNAPSHOT.jar, 
          moduleB-0.0.1-SNAPSHOT.jar, 
          .... more
          moduleN-0.0.1-SNAPSHOT.jar define 1 overlapping resource: 
[WARNING]   - META-INF/MANIFEST.MF
[WARNING] maven-shade-plugin has detected that some class files are
[WARNING] present in two or more JARs. When this happens, only one
[WARNING] single version of the class is copied to the uber jar.
[WARNING] Usually this is not harmful and you can skip these warnings,
[WARNING] otherwise try to manually exclude artifacts based on
[WARNING] mvn dependency:tree -Ddetail=true and the above output.
[WARNING] See http://maven.apache.org/plugins/maven-shade-plugin/

How fix to remove that warning message?, It mostly because all my modules do not have the META/MANIFEST.MF file in their src/main/resources directories

3

There are 3 best solutions below

0
On BEST ANSWER

Adding this in the configuration will exclude the resource files from the build

<filters>
   <filter>
      <artifact>org.example:*</artifact>
      <excludes>
         <exclude>META-INF/*.MF</exclude>
      </excludes>
   </filter>
</filters>
0
On

After using Badea's answer, I still wanted to have my final MANIFEST.MF file. Adding this to my pom.xml seems to have fixed it. Just leaving this here as this was the top google result when searching for this problem :).

<transformers>
    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
</transformers>
0
On

This is what actually worked for me:

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>3.5.2</version>
      <configuration>
        <filters>
          <filter>
            <artifact>*.*</artifact>
            <excludes>
              <exclude>module-info.class</exclude>
              <exclude>META-INF/MANIFEST.MF</exclude>
            </excludes>
          </filter>
        </filters>
        <transformers>
          <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
            <manifestEntries>
              <Main-Class>com.yourpackage.YourApp</Main-Class>
            </manifestEntries>
          </transformer>
        </transformers>
      </configuration>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
        </execution>
      </executions>
    </plugin>