1. 设置仓库,我的Settings里设置使用了公司的Nexus
<?xml version="1.0"?> <settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository>D:mavenrepo</localRepository> <servers> <server> <id>snapshots</id> <username>snapshots</username> <password>xxx</password> <filePermissions>664</filePermissions> <directoryPermissions>775</directoryPermissions> </server> </servers> <distributionManagement> <repository> <id>releases</id> <name>xxx Nexus Releases</name> <url>xxxx</url> </repository> <snapshotRepository> <uniqueVersion>false</uniqueVersion> <id>snapshots</id> <name>xxx Nexus Snapshots</name> <url>xxxxx</url> </snapshotRepository> </distributionManagement> <profiles> <profile> <id>xxxNexus</id> <repositories> <repository> <id>xxxNexus</id> <url>xxx</url> <releases> <enabled>true</enabled> <!-- always , daily (default), interval:X (where X is an integer in minutes) or never. --> <updatePolicy>daily</updatePolicy> <checksumPolicy>warn</checksumPolicy> </releases> <snapshots> <enabled>true</enabled> <checksumPolicy>fail</checksumPolicy> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>xxxNexus</id> <url>xxxx</url> <releases> <enabled>true</enabled> <checksumPolicy>warn</checksumPolicy> </releases> <snapshots> <enabled>true</enabled> <checksumPolicy>fail</checksumPolicy> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>xxxNexus</activeProfile> </activeProfiles> </settings>
2.发现重复类,执行命令
mvn -U clean package -Plocal -Dmaven.test.skip=true enforcer:enforce -DcheckDeployRelease_skip=true
-Dmaven.test.skip=true: 如果命令包含了test phase,则忽略单元测试
enforcer:enforce: 查找重复类
-DcheckDeployRelease_skip: 不知道什么意思
执行命令后,输出如下
可以发现 jcl-over-slf4j 与 commons-logging 包有重复类冲突
3. 在pom里查找重复类冲突的包并排除重复类冲突
由于在我的pom里并没有显式写入common-logging的dependency,所以我们需要查找那个jar包依赖了commons-logging,执行如下命令
mvn -U dependency:tree -Dverbose
发现如下片段
在这个叫qsso-client的库里依赖了commons-logging包,所以我们在pom里将其排除
3. 排除重复类
<dependency> <groupId>com.xxx.security</groupId> <artifactId>qsso-client</artifactId> <version>${qsso-client.version}</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency>
这样就将qsso-client的commons-logging包排除了,之后再运行enforcer:enforce则不会再报错