获取不包括测试依赖项的 Maven 依赖项列表
Get a list of maven dependencies excluding test dependencies
我想获取我的 Maven 项目的所有依赖项的列表,但没有使用 Maven 3.6.2 的测试依赖项。
列出我成功使用 dependency:tree
或 dependency:list
的所有依赖项。
然后我尝试添加 -DincludeScope=compile
和 -DexcludeScope=test
作为参数。添加这些后,我仍然包含测试依赖项。
示例命令
mvn -f example/location/pom.xml dependency:tree -DincludeScope=compile -DexcludeScope=test
输出
...
...
...
\- junit:junit:jar:4.12:test
\- org.hamcrest:hamcrest-core:jar:1.3:test
父依赖为test,子依赖为compile
我还发现了另一个问题。如果父依赖项是 test
那么我不想看到它的任何依赖项。
...
...
| +- com.google.cloud:google-cloud-core-grpc:jar:1.52.0:test
| | +- com.google.auth:google-auth-library-credentials:jar:0.11.0:compile
如何删除所有测试依赖项及其子项?
includeScope
和 excludeScope
不是 dependency:tree
Mojo so they will have no effect. Depending on your maven-plugin-dependency
version scope
parameter might work (see MSHARED-4 的参数):
mvn dependency:tree -Dscope=compile
我想获取我的 Maven 项目的所有依赖项的列表,但没有使用 Maven 3.6.2 的测试依赖项。
列出我成功使用 dependency:tree
或 dependency:list
的所有依赖项。
然后我尝试添加 -DincludeScope=compile
和 -DexcludeScope=test
作为参数。添加这些后,我仍然包含测试依赖项。
示例命令
mvn -f example/location/pom.xml dependency:tree -DincludeScope=compile -DexcludeScope=test
输出
...
...
...
\- junit:junit:jar:4.12:test
\- org.hamcrest:hamcrest-core:jar:1.3:test
父依赖为test,子依赖为compile
我还发现了另一个问题。如果父依赖项是 test
那么我不想看到它的任何依赖项。
...
...
| +- com.google.cloud:google-cloud-core-grpc:jar:1.52.0:test
| | +- com.google.auth:google-auth-library-credentials:jar:0.11.0:compile
如何删除所有测试依赖项及其子项?
includeScope
和 excludeScope
不是 dependency:tree
Mojo so they will have no effect. Depending on your maven-plugin-dependency
version scope
parameter might work (see MSHARED-4 的参数):
mvn dependency:tree -Dscope=compile