maven 是常用的jar包管理工具之一夺谁。在引入的jar包多了之后往往會有同一個jar包的不同版本都被引入的情況逾雄, 這個時候需要將不用的jar包進行排除铁瞒。 雖然可以使用mvn dependency:tree
來查看所有引入的jar包摧玫, 但要從中找出哪些jar包有多個版本往往很困難咳促。 下面介紹一個maven plugin 可以幫助我們快速找出哪些java類重復了弱判。
duplicate-finder-maven-plugin 引入
<build>
<plugins>
<plugin>
<groupId>org.basepom.maven</groupId>
<artifactId>duplicate-finder-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<id>default</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>false</skip>
<quiet>false</quiet>
<checkCompileClasspath>true</checkCompileClasspath>
<checkRuntimeClasspath>true</checkRuntimeClasspath>
<checkTestClasspath>true</checkTestClasspath>
<failBuildInCaseOfDifferentContentConflict>false</failBuildInCaseOfDifferentContentConflict>
<failBuildInCaseOfEqualContentConflict>false</failBuildInCaseOfEqualContentConflict>
<failBuildInCaseOfConflict>false</failBuildInCaseOfConflict>
<printEqualFiles>false</printEqualFiles>
<preferLocal>true</preferLocal>
<!-- Version 1.1.1+ -->
<includeBootClasspath>false</includeBootClasspath>
<bootClasspathProperty>sun.boot.class.path</bootClasspathProperty>
<!-- Version 1.1.1+ -->
<!-- Version 1.2.0+ -->
<includePomProjects>false</includePomProjects>
<!-- Version 1.2.0+ -->
</configuration>
</plugin>
</plugins>
</build>
duplicate-finder-maven-plugin 執(zhí)行
mvn duplicate-finder:check
輸出example
[WARNING] Found duplicate and different classes in [com.alibaba.external:misc.javassist:3.9.0.GA, org.javassist:javassist:3.18.0-GA]:
[WARNING] javassist.ByteArrayClassPath
[WARNING] javassist.CannotCompileException
[WARNING] javassist.ClassClassPath
[WARNING] javassist.ClassMap
[WARNING] javassist.ClassPath
[WARNING] javassist.ClassPathList
....