首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >org.apache.maven.plugins.enforcer.BanDuplicateClasses失败,并显示消息:找到重复的类

org.apache.maven.plugins.enforcer.BanDuplicateClasses失败,并显示消息:找到重复的类
EN

Stack Overflow用户
提问于 2020-01-06 01:47:03
回答 1查看 1.1K关注 0票数 0

我将以下wiremock依赖项添加到我的项目中:

代码语言:javascript
复制
<dependency>
  <groupId>com.github.tomakehurst</groupId>
  <artifactId>wiremock-standalone</artifactId>
  <version>2.25.1</version>
  <scope>test</scope>
</dependency>

这将失败,并返回错误:

代码语言:javascript
复制
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.BanDuplicateClasses failed with message:
Duplicate classes found:

  Found in:
    org.slf4j:slf4j-api:jar:1.7.7:compile
    com.github.tomakehurst:wiremock-standalone:jar:2.25.1:test
  Duplicate classes:
    org/slf4j/helpers/SubstituteLogger.class
    org/slf4j/ILoggerFactory.class
    org/slf4j/helpers/BasicMDCAdapter.class
    org/slf4j/MDC.class
    org/slf4j/LoggerFactory.class
    org/slf4j/spi/MDCAdapter.class
    org/slf4j/helpers/Util.class
    org/slf4j/helpers/NOPLogger.class
    org/slf4j/helpers/NOPLoggerFactory.class
    org/slf4j/helpers/SubstituteLoggerFactory.class
    org/slf4j/helpers/NamedLoggerBase.class
    org/slf4j/helpers/NOPMDCAdapter.class
    org/slf4j/MarkerFactory.class
    org/slf4j/Logger.class
    org/slf4j/Marker.class
    org/slf4j/helpers/FormattingTuple.class
    org/slf4j/helpers/BasicMarker.class
    org/slf4j/spi/LoggerFactoryBinder.class
    org/slf4j/helpers/MarkerIgnoringBase.class
    org/slf4j/spi/LocationAwareLogger.class
    org/slf4j/helpers/MessageFormatter.class
    org/slf4j/helpers/BasicMarkerFactory.class
    org/slf4j/IMarkerFactory.class
    org/slf4j/spi/MarkerFactoryBinder.class

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.197 s
[INFO] Finished at: 2020-01-05T17:45:50Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.1.1:enforce (enforce-maven) on project project-webapp: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]

因此我添加了一个排除项:

代码语言:javascript
复制
<dependency>
  <groupId>com.github.tomakehurst</groupId>
  <artifactId>wiremock-standalone</artifactId>
  <version>2.25.1</version>
  <exclusions>
    <exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </exclusion>
  </exclusions>
  <scope>test</scope>
</dependency>

但我收到了相同的错误消息。我的排除正确吗?我使用mvn clean compile命令构建项目

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-06 02:24:05

基于这个项目,我可以看到wiremock-standalone是一个shade- ...in,这意味着它包含了几个jar文件,包含在一个单独的jar jar中,最后你不能排除任何东西。您唯一的选择是检查是否可以使用其他jar文件而不是-standalone ...

您可以查看jar文件:

代码语言:javascript
复制
unzip -t  wiremock-standalone-2.25.1.jar
 ..
testing: org/                     OK
testing: org/slf4j/               OK
testing: org/slf4j/event/         OK
testing: org/slf4j/event/EventConstants.class   OK
testing: org/slf4j/event/EventRecodingLogger.class   OK
testing: org/slf4j/event/Level.class   OK
testing: org/slf4j/event/LoggingEvent.class   OK
testing: org/slf4j/event/SubstituteLoggingEvent.class   OK
testing: org/slf4j/helpers/       OK
testing: org/slf4j/helpers/BasicMarker.class   OK
testing: org/slf4j/helpers/BasicMarkerFactory.class   OK
testing: org/slf4j/helpers/BasicMDCAdapter$1.class   OK
testing: org/slf4j/helpers/BasicMDCAdapter.class   OK
testing: org/slf4j/helpers/FormattingTuple.class   OK
testing: org/slf4j/helpers/MarkerIgnoringBase.class   OK
testing: org/slf4j/helpers/MessageFormatter.class   OK
testing: org/slf4j/helpers/NamedLoggerBase.class   OK
testing: org/slf4j/helpers/NOPLogger.class   OK
testing: org/slf4j/helpers/NOPLoggerFactory.class   OK
testing: org/slf4j/helpers/NOPMDCAdapter.class   OK
testing: org/slf4j/helpers/SubstituteLogger.class   OK
testing: org/slf4j/helpers/SubstituteLoggerFactory.class   OK
testing: org/slf4j/helpers/Util$1.class   OK
testing: org/slf4j/helpers/Util$ClassContextSecurityManager.class   OK
testing: org/slf4j/helpers/Util.class   OK
testing: org/slf4j/ILoggerFactory.class   OK
testing: org/slf4j/IMarkerFactory.class   OK
testing: org/slf4j/Logger.class   OK
testing: org/slf4j/LoggerFactory.class   OK
testing: org/slf4j/Marker.class   OK
testing: org/slf4j/MarkerFactory.class   OK
testing: org/slf4j/MDC$1.class    OK
testing: org/slf4j/MDC$MDCCloseable.class   OK
testing: org/slf4j/MDC.class      OK
testing: org/slf4j/spi/           OK
testing: org/slf4j/spi/LocationAwareLogger.class   OK
testing: org/slf4j/spi/LoggerFactoryBinder.class   OK
testing: org/slf4j/spi/MarkerFactoryBinder.class   OK
testing: org/slf4j/spi/MDCAdapter.class   OK
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59602570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档