如何避免 Maven 构建中的 "Overlappping classes" 警告?

How to avoid the "Overlappping classes" warning in a maven build?

我有一个模块依赖于其他两个项目,但我在构建项目时遇到了这个问题。

虽然没有出现错误,但我收到很多关于重叠相同内容的警告 class:

[WARNING] commons-logging-1.2.jar, jcl-over-slf4j-1.7.12.jar define 6 overlappping classes: 
[WARNING]   - org.apache.commons.logging.impl.SimpleLog
[WARNING]   - org.apache.commons.logging.Log
[WARNING]   - org.apache.commons.logging.impl.SimpleLog
[WARNING]   - org.apache.commons.logging.LogConfigurationException
[WARNING]   - org.apache.commons.logging.impl.NoOpLog
[WARNING]   - org.apache.commons.logging.LogFactory
[WARNING] aspectjrt-1.7.0.jar, aspectjweaver-1.8.6.jar define 128 overlappping classes: 
[WARNING]   - org.aspectj.internal.lang.reflect.SignaturePatternImpl
[WARNING]   - org.aspectj.runtime.reflect.SignatureImpl
[WARNING]   - org.aspectj.internal.lang.reflect.DeclareSoftImpl
[WARNING]   - org.aspectj.lang.reflect.AjType
[WARNING]   - org.aspectj.lang.JoinPoint$StaticPart
[WARNING]   - org.aspectj.runtime.internal.cflowstack.ThreadStackImpl11
[WARNING]   - org.aspectj.runtime.internal.cflowstack.ThreadStack
[WARNING]   - org.aspectj.internal.lang.reflect.InterTypeDeclarationImpl
[WARNING]   - org.aspectj.internal.lang.reflect.DeclareAnnotationImpl
[WARNING]   - org.aspectj.lang.annotation.SuppressAjWarnings
[WARNING]   - 118 more...
[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 skeep 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
[INFO] Replacing original artifact with shaded artifact.

如何避免这些警告?

使用 Maven plugin Dependency Tree,并使用

mvn clean dependency:tree
# or (mvn 3)
mvn clean org.apache.maven.plugins:maven-dependency-plugin:3.0.1:tree

clean 对于避免旧 target 内容的任何副作用很重要。

然后,根据您使用的插件,您可以添加排除规则,如this answer,以避免这些错误消息。

MRUNIT-209 中所示,dependency-tree 的 2.5.1 版本不 运行 与 Maven 3.x.x。
使用全名org.apache.maven.plugins:maven-dependency-plugin:3.0.1:tree会强制使用3.0.1版本的maven-dependency-plugin.