5

is there any way to exclude dependencies used during test goal? For example I would like to avoid having all *:tests jar printed by mvn dependency:tree.

[INFO] Building test 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ test ---
[INFO] com.test.test:jar:1.0-SNAPSHOT
[INFO] +- junit:junit:jar:4.13:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.specs2:specs2-core_2.13:jar:4.8.3:test
[INFO] |  +- org.specs2:specs2-matcher_2.13:jar:4.8.3:test
[INFO] |  +- org.specs2:specs2-common_2.13:jar:4.8.3:test
[INFO] |  |  +- org.specs2:specs2-fp_2.13:jar:4.8.3:test
[INFO] |  |  \- org.scala-lang.modules:scala-parser-combinators_2.13:jar:1.1.2:compile
[INFO] |  \- org.scala-sbt:test-interface:jar:1.0:test
[INFO] +- org.scalatest:scalatest_2.13:jar:3.1.0:test
[INFO] |  +- org.scalactic:scalactic_2.13:jar:3.1.0:test
[INFO] |  +- org.scala-lang:scala-reflect:jar:2.13.1:test
[INFO] \- com.fasterxml.jackson.core:jackson-databind:jar:2.10.2:compile

Many jars are used during the compile phase while others during test phase. I was looking to the:

mvn dependency:tree -Dexcludes=org.apache.maven*

so I was wondering if it is possible to directly exclude all *tests via the command line.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Prisco
  • 653
  • 1
  • 15
  • 30

1 Answers1

17

You can add the scope like this:

mvn dependency:tree -Dscope=compile
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • I have not tried it but following the documentation (https://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html) it does not work ("currently"). – J Fabian Meier Apr 15 '20 at 08:48
  • Maybe the documentation is outdated or fails to specify the scenarios it fails? It worked for my usecase with -Dscope=compile. I see the provided and compile scope and test is filtered. Maybe it's a bug because only compile should have been shown? – joseph Jan 07 '22 at 20:48
  • If you think there is a bug open an issue https://maven.apache.org/plugins/maven-dependency-plugin/issue-management.html – khmarbaise Jan 08 '22 at 10:32
  • 2
    This worked well for me with Maven 3.8.5. To include both runtime and compile dependencies, I used `mvn dependency:tree -Dscope=runtime`. – Asa Jul 29 '22 at 18:31