Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven brings "test" transitive dependency as "compile"

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

like image 960
kan Avatar asked Jul 04 '14 18:07

kan


People also ask

Are compile dependencies transitive?

It is not transitive. This scope indicates that the dependency is not required for compilation, but is for execution. Maven includes a dependency with this scope in the runtime and test classpaths, but not the compile classpath.

Does Maven support transitive dependencies?

Maven automatically includes required transitive dependencies in our project. We can list all dependencies including transitive dependencies in the project using mvn dependency:tree command.

How does Maven determine transitive dependency?

You can get this information in the Maven Tool Window. First go to View → Tool Windows → Maven, to make sure that the Maven window is visible. The top-level elements in the tree are your direct dependencies, and the child elements are the transitive dependencies.


1 Answers

Study the output of the following Maven command.

mvn -X dependency:tree -Dverbose

That should tell you why Maven upgraded the scope from test to compile.

like image 165
klr8 Avatar answered Oct 11 '22 17:10

klr8