maven 工程pom依赖优化及常用命令
本文为博主原创,转载请注明出处:
mvn dependency:list -Dverbose
该命令可以列出项目依赖的所有jar包,-Dverbose参数会把被忽略的jar,即相同jar包的不同版本引入也列出来。
输出示例:
2.mvn dependency:tree
mvn dependency:tree -Dverbose
这个命令跟上一个命令的区别就是,这个命令的依赖,输出来是个树,更方便看依赖关系。
输出示例:
2.1 查看某一个包的依赖树
mvn dependency:tree -Dverbose -Dincludes=commons-collections
3
mvn dependency:analyze -Dverbose
mvn dependency:analyze命令可以分析当前项目的依赖,我们可以根据这个结果删除多余的依赖。
[INFO] Used declared dependencies found: [INFO] com.alibaba:fastjson:jar:1.2.73:compile [INFO] org.hibernate:hibernate-validator:jar:5.3.6.Final:compile [INFO] io.springfox:springfox-swagger2:jar:2.7.0:compile [INFO] junit:junit:jar:4.12:test [INFO] joda-time:joda-time:jar:2.9.9:compile [WARNING] Used undeclared dependencies found: [WARNING] io.springfox:springfox-spi:jar:2.7.0:compile [WARNING] com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile [WARNING] io.springfox:springfox-core:jar:2.7.0:compile [WARNING] org.apache.commons:commons-lang3:jar:3.5:compile [WARNING] org.slf4j:slf4j-api:jar:1.7.25:compile [WARNING] org.springframework:spring-web:jar:4.3.16.RELEASE:compile [WARNING] javax.validation:validation-api:jar:1.1.0.Final:compile [WARNING] org.jasig.cas.client:cas-client-core:jar:3.3.3:compile [WARNING] io.springfox:springfox-spring-web:jar:2.7.0:compile [WARNING] net.logstash.logback:logstash-logback-encoder:jar:4.11:compile [WARNING] org.springframework:spring-beans:jar:4.3.16.RELEASE:compile [WARNING] Unused declared dependencies found: [WARNING] org.apache.tomcat.embed:tomcat-embed-jasper:jar:8.5.29:provided [WARNING] org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.12.RELEASE:provided [WARNING] org.projectlombok:lombok:jar:1.18.12:provided [WARNING] org.springframework:spring-test:jar:4.3.16.RELEASE:test [WARNING] org.springframework.boot:spring-boot-loader:jar:1.5.12.RELEASE:provided [WARNING] io.springfox:springfox-swagger-ui:jar:2.7.0:compile [INFO] ------------------------------------------------------------------------
mvn dependency:analyze 的执行结果会将 pom 的依赖解析成三部分: Used declared dependencies、Used undeclared dependencies、Unused declared dependencies 三部分,可以根据 Unused declared dependencies 中的依赖进行优化;从pom中进行相应的删除,从而减少依赖;
4
mvn dependency:analyze-duplicate
分析 pom 中是否存在重复配置的依赖:其执行结果如下: