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

时间:2020-01-05 17:47:03

标签: java maven

我在项目中添加了以下wiremock依赖项:

<dependency>
  <groupId>com.github.tomakehurst</groupId>
  <artifactId>wiremock-standalone</artifactId>
  <version>2.25.1</version>
  <scope>test</scope>
</dependency>

哪个失败并出现错误:

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

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

<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

构建项目

1 个答案:

答案 0 :(得分:1)

基于项目,我可以看到独立的Wiremock是一个jar容器,这意味着它包含多个jar文件,这些文件包含在单个jar中...最终您不能排除任何东西。您唯一的选择是检查是否可以使用其他jar文件代替-standalone ...

您可以查看jar文件:

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
相关问题