问题:在Maven项目中,如何查看某个包是由pom.xml文件的哪个依赖引入的?
示例:
mvn dependency:tree -Dverbose -Dincludes=jakarta.validation:jakarta.validation-api
或者:
mvn dependency:tree -Dincludes=velocity:velocity
mvn dependency:tree命令的作用是输出依赖树,参数Dincludes和Dexcludes则用来指定或排除特定的依赖。Dincludes的完整格式是 [groupId]:[artifactId]:[type]:[version]
1
示例1的输出为:
可见在此项目中,jakarta.validation:jakarta.validation-api这个包是由org.springframework.boot:spring-boot-starter-validation:jar:2.7.10这个依赖引入的。
此命令还可用来辅助分析包冲突2
另注:不知何故,我运行mvn dependency:tree -Dverbose -Dincludes=jakarta.validation:jakarta.validation-api 命令时报错了,给两参数都加上双引号才达到目的:mvn dependency:tree "-Dverbose" "-Dincludes=jakarta.validation:jakarta.validation-api"
https://maven.apache.org/plugins/maven-dependency-plugin/examples/filtering-the-dependency-tree.html ↩︎
CSDN:maven的mvn dependency依赖分析和常用命令介绍 ↩︎