Maven Shade 插件:如何解决警告消息“定义 1 个重叠资源:[警告] - META-INF/MANIFEST.MF”

问题描述 投票:0回答:3

为了

  <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>

插件运行良好,但总是出现此消息:

[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/

如何修复以删除该警告消息?,主要是因为我的所有模块在其

META/MANIFEST.MF
目录中都没有
src/main/resources
文件

maven maven-3 maven-shade-plugin
3个回答
13
投票

在配置中添加此内容将从构建中排除资源文件

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

8
投票

使用Badea的答案后,我仍然想拥有最终的MANIFEST.MF文件。将其添加到我的 pom.xml 似乎已经修复了它。只需将其留在这里,因为这是搜索此问题时的最佳谷歌结果:)。

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

0
投票

这对我来说确实有效:

    <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>
© www.soinside.com 2019 - 2024. All rights reserved.