Maven Dependency 查找java重复类

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 执行

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
....

更多duplicate-finder-maven-plugin信息

    原文作者:DongGuangqing
    原文地址: https://www.jianshu.com/p/cf0ab4c1d19a
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞