Maven 构建 [警告] 我们有一个重复的类 [英] Maven build [WARNING] we have a duplicate class
问题描述
有人知道我的 Maven 构建发生了什么事情吗?我收到了很多重复的警告.
Anybody has any idea what happened to my maven build? I am getting a lot of duplicate warnings.
[WARNING] We have a duplicate org/apache/commons/logging/impl/LogFactoryImpl$1.class in /home/shengjie/.m2/repository/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar
[WARNING] We have a duplicate org/apache/commons/logging/impl/LogFactoryImpl.class in /home/shengjie/.m2/repository/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar
[WARNING] We have a duplicate org/apache/commons/logging/impl/NoOpLog.class in /home/shengjie/.m2/repository/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar
[WARNING] We have a duplicate org/apache/commons/logging/impl/SimpleLog$1.class in /home/shengjie/.m2/repository/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar
[WARNING] We have a duplicate org/apache/commons/logging/impl/SimpleLog.class in /home/shengjie/.m2/repository/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar
[WARNING] We have a duplicate org/apache/commons/logging/impl/Jdk14Logger.class in /home/shengjie/.m2/repository/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar
我查看了我的本地 m2 存储库,我在 commons-logging-api jar 中有两个类,LogFactoryImpl.class 和 LogFactoryImpl$1.class.与警告中提到的所有类相同.
I've looked into my local m2 repo, I have two classes there in commons-logging-api jar, LogFactoryImpl.class and LogFactoryImpl$1.class. Same as all the classes mentioned in the warnings.
要提到的一件事是我在 pom.xml 中使用了 shade 插件.
One thing to mention is that I am using shade plugin in my pom.xml.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.~~~~black out my own main class here~~~~~</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
我注意到依赖树看起来像下面
I noticed that the dependency tree looks like as below
[INFO] +- org.apache.cxf:cxf-bundle-jaxrs:jar:2.5.1:compile
[INFO] | - commons-logging:commons-logging:jar:1.1.1:compile
[INFO] - org.apache.hadoop.hive:hive-jdbc:jar:0.7.1-cdh3u3:compile
[INFO] - org.apache.hadoop.hive:hive-common:jar:0.7.1-cdh3u3:compile
[INFO] - commons-logging:commons-logging-api:jar:1.0.4:compile
和 commons-logging.jar 和 commons-logging-api.jar 都有 org/apache/commons/logging/LogFactory.class.
and commons-logging.jar and commons-logging-api.jar both have org/apache/commons/logging/LogFactory.class.
不知何故,Shad 插件最终试图将它们挤进一个大罐子里.然后出现警告.据说这是无视警告.但是我有点担心,如果有两个同名的重复类,应用程序如何知道应该使用哪个类?
somehow Shad plugin is trying to squeeze them in to a big fat jar at the end. then the warning is showing up. It's been said this is ignorable warning. But I am a bit worried, How does the application know what is the exact class should be used if there are two duplicated class with the same name?
推荐答案
查看 Maven 文档.
在您提供的示例中,我将从 org.apache.hadoop.hive 中排除
.在你的 pom.xml 中:commons-logging:commons-logging-api:jar:1.0.4:compile
依赖项:hive-common:jar:0.7.1-cdh3u3:compile
In your provided example, I'll exclude the commons-logging:commons-logging-api:jar:1.0.4:compile
dependency from org.apache.hadoop.hive:hive-common:jar:0.7.1-cdh3u3:compile
. In your pom.xml :
<dependency>
<groupId>org.apache.hadoop.hive</groupId>
<artifactId>hive-common:jar</artifactId>
<version>0.7.1-cdh3u3</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
</exclusion>
</exclusions>
</dependency>
这篇关于Maven 构建 [警告] 我们有一个重复的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!