这是我的项目POM (link to the paste, so you can right click > save as pom.xml)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zybnet</groupId>
<artifactId>excel-reporter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mvn1</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.8</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.6.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${project.build.sourceDirectory}</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<finalName>${artifactId}-${version}-tmp</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.7.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.zybnet.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我遵循了the FAQ中公布的配置默认jar插件的建议,但是当我运行mvn package
时,仍会发出大约20K的警告。运行mvn clean
也无济于事。
根据this answer,我可以手动排除某些依赖项。但是,我不知道它是否是正确的方式,并且依赖树相当复杂,因此很难争论从哪里开始。
我知道这些问题无害,但我习惯将警告视为必须修复的问题。此外,我是Maven的初学者,所以我想了解我的理解有什么问题,以及如何解决问题。
(此处不能使用maven程序集插件)
答案 0 :(得分:27)
有时会发生在两个或多个JAR文件中找到相同的类定义(通常这些是依赖项JAR)。在这种情况下,除了试图找出从依赖项或最终工件中手动排除的内容(可能在mvn dependency:tree -Ddetail=true
的帮助下)之外,开发人员无法做任何事情。我opened an issue and submitted a patch,帮助开发人员输出一些稍微漂亮的输出,比如
[WARNING] xml-apis-1.3.02.jar, xmlbeans-2.3.0.jar define 4 overlappping classes:
[WARNING] - org.w3c.dom.TypeInfo
[WARNING] - org.w3c.dom.DOMConfiguration
[WARNING] - org.w3c.dom.DOMStringList
[WARNING] - org.w3c.dom.UserDataHandler
[WARNING] maven-shade-plugin has detected that some .class files
[WARNING] are present in two or more JARs. When this happens, only
[WARNING] one single version of the class is copied in the uberjar.
[WARNING] Usually this is not harmful and you can skip these
[WARNING] warnings, otherwise try to manually exclude artifacts
[WARNING] based on mvn dependency:tree -Ddetail=true and the above
[WARNING] output
[WARNING] See http://docs.codehaus.org/display/MAVENUSER/Shade+Plugin
使用此输出和来自mvn dependency:tree
的输出我添加了
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.7.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</exclusion>
<exclusion>
<groupId>bouncycastle</groupId>
<artifactId>bcmail-jdk14</artifactId>
</exclusion>
<exclusion>
<groupId>bouncycastle</groupId>
<artifactId>bcprov-jdk14</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bctsp-jdk14</artifactId>
</exclusion>
</exclusions>
</dependency>
并设法将警告数量从几千减少到几十。不过,这并不完美。尽管如此,他们还是会继续使用会导致名称冲突的类(我无法理解为什么)。不过,这个解决方案特定于这个特定的项目,并且不能轻易地移植到任何其他项目上。
答案 1 :(得分:2)
对此问题的更新更新是更新到当前的maven插件。 问题是使用
<version>1.7.1</version>
只会告诉你:
We have a duplicate org/eclipse/persistence/internal/libraries/asm/AnnotationVisitor.class in /Users/.../repository/org/eclipse/persistence/eclipselink/2.7.0/eclipselink-2.7.0.jar
让您猜测或试错,其中第一个条目是重叠类。不是很有用。 Fortunatly,
<version>3.1.0</version>
将为您提供更有用的输出,包括它们来自的罐子: 例如
annotations-3.0.1.jar, jcip-annotations-1.0.jar define 4 overlapping classes:
- net.jcip.annotations.GuardedBy
- net.jcip.annotations.NotThreadSafe
...
然后您可以决定排除其中一个,或使用阴影根据您的项目重命名这些类。