我将以下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命令构建项目
发布于 2020-01-06 02:24:05
基于这个项目,我可以看到wiremock-standalone是一个shade- ...in,这意味着它包含了几个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 OKhttps://stackoverflow.com/questions/59602570
复制相似问题