Maven brings "test" transitive dependency as "compile"

java, maven, maven-3

Solution

I had a similar problem.

In my case an entry in the dependencyManagement of a parent pom set the scope of the dependent artefact to compile. Actually I omitted the scope tag which effectively is the same as setting it to compile. Changing it to provided helped. Seems the scope in dependencyManagement takes precedence over the transitive scope. Which makes sense but can still cause confusion when all you wanted to do is define the version.

It was actually not hard to spot: Looking at the effective-pom showed the dependencyManagement entry.

Problem

When I run "mvn dependency:tree" for my project it shows the following: ``` [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ xxxxx --- [INFO] com.xxx.xxx:xxxxx:war:3.1.0-SNAPSHOT ... [INFO] +- commons-configuration:commons-configuration:jar:1.5:compile [INFO] | \- commons-beanutils:commons-beanutils-core:jar:1.7.0:compile [INFO] +- org.seleniumhq.selenium:selenium-api:jar:2.34.0:test [INFO] | +- com.google.guava:guava:jar:14.0:test [INFO] | \- org.json:json:jar:20080701:test [INFO] +- org.seleniumhq.selenium:selenium-htmlunit-driver:jar:2.34.0:test [INFO] | +- org.seleniumhq.selenium:selenium-remote-driver:jar:2.34.0:test [INFO] | | +- cglib:cglib-nodep:jar:2.1_3:test [INFO] | | +- net.java.dev.jna:jna:jar:3.4.0:test [INFO] | | \- net.java.dev.jna:platform:jar:3.4.0:test [INFO] | \- net.sourceforge.htmlunit:htmlunit:jar:2.12:test [INFO] | +- org.apache.commons:commons-lang3:jar:3.1:test [INFO] | +- org.apache.httpcomponents:httpmime:jar:4.2.3:test [INFO] | +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.12:test [INFO] | +- xerces:xercesImpl:jar:2.10.0:test >>>[INFO] | | \- xml-apis:xml-apis:jar:1.4.01:compile [INFO] | +- net.sourceforge.nekohtml:nekohtml:jar:1.9.18:test [INFO] | +- net.sourceforge.cssparser:cssparser:jar:0.9.9:test [INFO] | | \- org.w3c.css:sac:jar:1.3:test [INFO] | \- org.eclipse.jetty:jetty-websocket:jar:8.1.9.v20130131:test [INFO] +- org.seleniumhq.selenium:selenium-firefox-driver:jar:2.34.0:test ... ``` As you see on the marked line, the xml-apis has "compile" scope, and as result it is packed into .war file. Why could it happen? More interestingly it happens only while Java5 is used, for Java6 the dependency appears as "test". Maven version: 3.0.4

Original source