2

Why does adding the following result in compile scope dependencies?

<dependency>
  <groupId>myproject.core</groupId>
  <artifactId>api</artifactId>
  <classifier>tests</classifier>
  <scope>test</scope>
</dependency>

[INFO] +- myproject.core:api:jar:tests:5.0.5-SNAPSHOT:test
[INFO] |  +- org.apache.curator:curator-framework:jar:2.7.1:compile
[INFO] |  |  \- org.apache.curator:curator-client:jar:2.7.1:compile
[INFO] |  +- org.apache.curator:curator-x-discovery:jar:2.7.1:compile
[INFO] |  |  +- org.apache.curator:curator-recipes:jar:2.7.1:compile

I'd expect copy-dependencies with an exclusion on test scope to not only skip the top level but remove it and its transitives from the tree.

Peter Kahn
  • 12,364
  • 20
  • 77
  • 135

1 Answers1

0

There is a difference between test dependencies and test-jar dependencies.

For test dependencies, the scope of transitive dependencies are correctly set to test (see this table in the Maven reference).

For test-jar dependencies (what you have here), the behaviour is different. I couldn't find anything in the Maven docs explaining why it is different (maybe someone else with better insight can explain why). However, I found a bug report (MNG-1378) about this, which remains unresolved after more than 10 years, so I would not get your hopes up.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • Ok, so I'm not crazy, maven is simply a little broken. So, my work around would be to push tests or test utility code into their own modules. I don't love it but it's a viable option. – Peter Kahn Sep 22 '15 at 14:52