Maven dependency resolution and scope overriding - maven

Disclaimer
(I originally asked the question in a very detailed manner over here. I've excerpted it here as the maven-users mailing list has gone quiet on this question.) (not just another newbie question)
Reference
My reference material is
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Management; please let me know in this discussion if this is outdated or wrong.
Question
There is a section in that document that begins with "A second, and very important...". In what follows I'll refer to that section's projects A and B, and will excerpt from them.
In that section, you will see that project A has a <dependencyManagement> section that--among other things--defines an artifact, c, as having scope compile:
<!-- In A's pom.xml; condensed for brevity -->
<dependencyManagement>
<dependency>
<groupId>test</groupId>
<artifactId>c</artifactId>
<version>1.0</version>
<scope>compile</scope> <!-- look: compile scope -->
</dependency>
</dependencyManagement>
Then you will see a pom.xml for project B that (a) inherits from project A (thus inheriting its dependencyManagement section) and (b) establishes a dependency on artifact c, without having to specify its version. You will also notice that the dependency on artifact c overrides the scope of c to be runtime, not compile:
<!-- In B's pom.xml, whose parent is A's pom.xml (above); condensed for brevity -->
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>c</artifactId>
<scope>runtime</scope> <!-- look: runtime scope -->
</dependency>
</dependencies>
Again, you'll note that there is no <version> element, but there is a <scope>runtime</scope> element.
My interpretation of this is that when all is said and done, B will depend on version 1.0 of artifact c in runtime scope, not compile scope.
Is that correct? My maven-ear-plugin bug rests on the fact that this is the expected behavior. It is not what happens when the maven-ear-plugin builds an .ear file.
Next, if that's correct, I would also expect that if artifact c had any transitive runtime dependencies they would be available in B's runtime classpath (as defined by the somewhat baffling table in http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope).
Is that correct?

Running mvn dependency:tree on the sample project posted in the bug link specified above,
[INFO] Building MEAR-143 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.3:tree (default-cli) # mear-143 ---
[INFO] ljnelson:mear-143:pom:1.0-SNAPSHOT
[INFO] \- junit:junit:jar:4.8.2:test
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MEAR-143 Leaf 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.3:tree (default-cli) # mear-143-leaf ---
[INFO] ljnelson:mear-143-leaf:jar:1.0-SNAPSHOT
[INFO] \- junit:junit:jar:4.8.2:test
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MEAR-143 Middle 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.3:tree (default-cli) # mear-143-middle ---
[INFO] ljnelson:mear-143-middle:jar:1.0-SNAPSHOT
[INFO] +- ljnelson:mear-143-leaf:jar:1.0-SNAPSHOT:runtime
[INFO] \- junit:junit:jar:4.8.2:test
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MEAR-143 EAR 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.3:tree (default-cli) # mear-143-ear ---
[INFO] ljnelson:mear-143-ear:ear:1.0-SNAPSHOT
[INFO] +- ljnelson:mear-143-middle:jar:1.0-SNAPSHOT:runtime
[INFO] | \- ljnelson:mear-143-leaf:jar:1.0-SNAPSHOT:test (scope managed from ru
ntime)
[INFO] \- junit:junit:jar:4.8.2:test
The dependency scope of mear-143-leaf in mear-143-middle, where the dependency is explicitly defined is indeed runtime, overriding the test scope defined in the dependencyManagement section of parent pom, mear-143.
In mear-143-ear, mear-143-leaf gets included transitively. Here the test scope defined in dependencyManagement of mear-143 takes precedence over the inherited runtime scope.
This, I guess is in line with what is specified in the second bullet point in the section you have referred above. Quoting it here and highlighting in bold and italics the relevant parts:
b is defined in B's parent's dependency management section and since
dependency management takes precedence over dependency mediation for
transitive dependencies, version 1.0 will be selected should it be
referenced in a or c's pom. b will also have compile scope

The selected answer is good enough to clarify the key point that whether dependencyManagement takes precedence relies on whether the child dependency is declared explicitly or transitively.
As a plus, I just created a summary concerned with version & scope resolution to kill this problem totally:
Assuming that a dependency A is declared eight times in different ways, and each with a different version... which version will win last?
just remember the three rules in the picture:
explicit declaration > dependency-management declaration > implicit transitive declaration
1st declaration > 2nd declaration
child declaration > parent declaration
and you will figure out the priority sequence shown as red numbered list in the picture.

Related

NoClassDefFoundError when running JPOS Q2?

Trying to setup JPOS Q2 for the first time through Maven / Intellij, and coming across an error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/osgi/framework/BundleException
at Q2_Main.main(Q2_Main.java:6)
Caused by: java.lang.ClassNotFoundException: org.osgi.framework.BundleException
at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 1 more
Process finished with exit code 1
I downloaded JPOS through maven, and I've tried looking at dozens of threads on the error but cannot resolve it on my own
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>Q2_JPOS_TEST</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.jpos</groupId>
<artifactId>jpos</artifactId>
<version>2.1.6</version>
</dependency>
</dependencies>
</project>
and I see it in my external libraries
jpos in external library
import org.jpos.q2.Q2;
public class Q2_Main {
public static void main(String[] args){
Q2 q2 = new Q2("src/main/java/deploy");
q2.start();
}
}
Edit for steps that I did:
File -> New Project -> Maven Project (created the POM automatically)
Pasted the JPOS dependency from my main project into new POM file
Maven Clean + Install from within Intellij Maven Panel
Created Q2_Main.java
Hit green play button, which results in that error
Edit 2:
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< org.example:Q2_JPOS_TEST >------------
[INFO] Building Q2_JPOS_TEST 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]-----------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) #
Q2_JPOS_TEST ---
[INFO] org.example:Q2_JPOS_TEST:jar:1.0-SNAPSHOT
[INFO] \- org.jpos:jpos:jar:2.1.6:compile
[INFO] +- commons-cli:commons-cli:jar:1.4:compile
[INFO] +- org.apache-extras.beanshell:bsh:jar:2.0b6:compile
[INFO] +- org.bouncycastle:bcprov-jdk15on:jar:1.67:compile
[INFO] +- org.bouncycastle:bcpg-jdk15on:jar:1.67:compile
[INFO] +- org.hdrhistogram:HdrHistogram:jar:2.1.12:compile
[INFO] +- org.javatuples:javatuples:jar:1.2:compile
[INFO] +- org.jdom:jdom2:jar:2.0.6:compile
[INFO] +- org.jline:jline:jar:3.19.0:compile
[INFO] \- org.slf4j:slf4j-api:jar:1.7.30:compile
[INFO] --------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] --------------------------------------------------------------
[INFO] Total time: 2.205 s
[INFO] Finished at: 2023-02-17T15:43:38-07:00
[INFO] --------------------------------------------------------------
I checked on the maven repository the library you are trying to use, jpos 2.1.6 (https://mvnrepository.com/artifact/org.jpos/jpos/2.1.6), and I've seen it has a series of runtime dependencies. It seems you miss org.osgi.core 6.0.0 judging from the stacktrace you posted. Make sure you have all the runtime dependencies needed in your classpath.
Here is a step by step of what I did to tun your code:
Create an empty folder /tmp/test-jpos
Write the file pom.xml there with the content you shared.
In IntelliJ menu File -> Open and opened the /tmp/test-jpos folder
Create dir src/main/java
Create file Q2_Main.java in that directory with content you shared.
Run the project by hitting the play run button (the green triangle)
With those steps it ran OK.
However that is not the recommended way to run Q2 I will expand on this later.

Dependency Graph in Spring Tool suite4 using Maven

I am working on resolving duplicate dependency issue. While solving I come to know that using dependency graph it will be easy. But I am not getting how to print a dependency Graph in STS4.
I have tried this command which I found in Maven Documentation
mvn dependency:tree -Dverbose -Dincludes=commons-collections
which is resulting :
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # attache-ui-web ---
[WARNING] Invalid POM for com.apple.ist.msol.attache:attache-api-entity:jar:3.0.0-SNAPSHOT, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] Invalid POM for com.apple.ist.msol.attache:attache-api-entity:jar:3.0.0-SNAPSHOT, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.972 s
[INFO] Finished at: 2019-09-17T09:30:23+05:30
[INFO] ------------------------------------------------------------------------
Can someone explain what does this result exactly mean and how to get dependency tree ?
When you open the pom.xml file in Eclipse/STS3/STS4, there is a tab to list all the dependencies as well as a tab for the dependency hierarchy. It shows you all the dependencies that you declared in your project as root nodes and their transitive dependencies as sub-nodes.

Maven - Reactors (Aggregation)

I have a maven project with a following directory structure:
trunk
| pom.xml
| coreutils
| | pom.xml
| | src
| budgetCap
| | pom.xml
| | src
The content of trunk/pom.xml is :
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
hxttp://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Ant2Maven</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>Parent Pom</name>
<modules>
<module>coreutils</module>
<module>budgetCap</module>
</modules>
In this structure, "budgetCap" is dependent on "coreutils",i.e. pom.xml of "budgetCap" contains a dependency of "coreutils"
Now I have two methods to build this project
First Method
Aggregation using Reactor
I will be inside trunk
So first of all I do mvn clean
shakim:trunk shakim.md$ mvn clean
Maven deletes the target folder of the two module in this order:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] coreutils
[INFO] budgetCap Maven Webapp
[INFO] Parent Pom
Now when i do mvn install
shakim:trunk shakim.md$ mvn install
Maven starts building modules in the following order:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] coreutils
[INFO] budgetCap Maven Webapp
[INFO] Parent Pom
In the given order, coreutils gets installed in the local repository successfully.
But budgetCap fails at the compilation giving an error that maven is unable to locate a class which was supposed to be produced by coreutils
the error message is as follows:
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building budgetCap Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # budgetCap ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # budgetCap ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 65 source files to /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/target/classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING]/Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/SingletonAggregator.java: /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/SingletonAggregator.java uses unchecked or unsafe operations.
[WARNING]/Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/SingletonAggregator.java: Recompile with -Xlint:unchecked for details.
[INFO] 2 warnings
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/BudgetCapServer.java:[41,34] package com.adiquity.request.utils does not exist
[ERROR] /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/utils/Utils.java:[9,34] package com.adiquity.request.utils does not exist
[ERROR] /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/log/data/parser/ConversionParser.java:[16,34] package com.adiquity.request.utils does not exist
Briefly speaking this package package com.adiquity.request.utils is actually present in coreutils, which this module budgetCap must have located successfully, but it is not.
Second Method
Go inside coreutils and do a
shakim:coreutils shakim.md$ mvn clean install
Go inside budgetCap and do a
shakim:budgetCap shakim.md$ mvn clean install
budgetCap compiles successfully without reporting any kind of error.
My question is that I want to use Reactors in Maven and I am unable to figure out why the build fails on using 1st method whereas 2nd method of building completes smoothly??
I am not sure how to use reactors, do we need to include anything in pom of coreutils and budgetCap signifying that pom of trunk is the parent.
Note: I don't want to use inheritance in this project

Maven says I have a cyclic reference in multi-module project but can't figure out why

I have a multi-module project that looks like this:
module1
pom.xml
module2
pom.xml
pom.xml
The pom.xml in module2 has a dependency on module1.
When I run mvn clean compile I get the following error:
The projects in the reactor contain a cyclic reference.
Here are my dependencies in module1:
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.48</version>
</dependency>
</dependencies>
I can't figure out why it says there is a cyclic reference. Even when I do mvn dependency:tree on module1 I get the following:
[INFO] +- log4j:log4j:jar:1.2.14:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.6.1:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO] +- com.jcraft:jsch:jar:0.1.48:compile
[INFO] \- junit:junit:jar:4.8.2:test
It looks to me like there aren't any references to module2 in module1. So where is the cyclic reference coming from?
Edit: Here is the log with debug on:
+ Error stacktraces are turned on.
Apache Maven 2.2.1 (r801777; 2009-08-06 15:16:01-0400)
Java version: 1.6.0_31
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='com.myorg:module2'}' and 'Vertex{label='com.myorg:module1'}' introduces to cycle in the graph com.myorg:module1 --> com.myorg:module2 --> com.myorg:module1
[INFO] ------------------------------------------------------------------------
[DEBUG] Trace
org.apache.maven.BuildFailureException: The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='com.myorg:module2'}' and 'Vertex{label='com.myorg:module1'}' introduces to cycle in the graph com.myorg:module1 --> com.myorg:module2 --> com.myorg:module1
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:295)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: hidden.org.codehaus.plexus.util.dag.CycleDetectedException: Edge between 'Vertex{label='com.myorg:module2'}' and 'Vertex{label='com.myorg:module1'}' introduces to cycle in the graph com.myorg:module1 --> com.myorg:module2 --> com.myorg:module1
at hidden.org.codehaus.plexus.util.dag.DAG.addEdge(DAG.java:143)
at hidden.org.codehaus.plexus.util.dag.DAG.addEdge(DAG.java:123)
at org.apache.maven.project.ProjectSorter.<init>(ProjectSorter.java:118)
at org.apache.maven.execution.ReactorManager.<init>(ReactorManager.java:99)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:288)
... 11 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Thu Jul 05 17:21:21 EDT 2012
[INFO] Final Memory: 3M/244M
[INFO] ------------------------------------------------------------------------
Ah! It was a misleading error.
The problem wasn't that there both module1 and module2 depended on each other. The problem was that module2 is a Maven plugin and in my root pom.xml I had the plugin in the section. I removed that plugin from the build and it started working.
It happened to me in this circumstances.
The module_child_X was specified 2 times at module_root pom.xml:
- As a module
(pom.xml of the root module)
<dependency>
<groupId>module_root</groupId>
<artifactId>module_child_X</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
- As a dependency
(pom.xml of the root module)
<modules>
<module>module_child_X</module>
...
</modules>
Solution?
Removed the module_child_X as a dependency. It is already specified as a module.
I do nearly the same, and I use IDEA.
I have a project A, which depends on a module B.
In the pom file of A, B was declared as a dependency. This is OK.
In the pom file of B, A was declared as its parent. I removed this information, and as it was requested in the error message I added the version number of B in its pom file.
And now it is OK.
I had exactly the same issue in a multimodule ear project. The ejb pom had a dependency on the web module (compile scope) and the web pom a dependency on the ejb module. As soon as i removed the ejb's pom dependency on the web module, the project build fine.
It makes sense that the intramodule dependencies must be unidirectional after all, in order to avoid cyclic references.

Maven - Different Dependency Version in Test

I'm suffering an issue similar to Maven 2 - different dependency versions in test and compile but the specified answer there does not work.
In my project I need to depend on a Cloudera distribution of Hadoop and a 'vanilla' version for JUnit testing, as the former only works on *nix.
When I try and execute my application, I get Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration. When I run JUnit tests from Maven or Eclipse, everything works fine. If I comment out the test dependencies, the application runs successfully.
Why is the compile dependency getting ignored when the test dependency is uncommented?
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>0.20.2-cdh3u2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-test</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
mvn dependency:list is shown below. The compile scoped version does not show up at all:
[INFO] The following files have been resolved:
[INFO] ant:ant:jar:1.6.5:test
[INFO] aopalliance:aopalliance:jar:1.0:compile
[INFO] asm:asm:jar:3.3.1:compile
[INFO] cglib:cglib:jar:2.2.2:compile
[INFO] ch.qos.logback:logback-classic:jar:1.0.0:compile
[INFO] ch.qos.logback:logback-core:jar:1.0.0:compile
[INFO] com.google.guava:guava:jar:r08:compile
[INFO] com.h2database:h2:jar:1.3.164:test
[INFO] com.jolbox:bonecp:jar:0.7.1.RELEASE:compile
[INFO] com.sun.jersey:jersey-core:jar:1.11:test
[INFO] commons-beanutils:commons-beanutils:jar:1.7.0:test
[INFO] commons-beanutils:commons-beanutils-core:jar:1.8.0:test
[INFO] commons-cli:commons-cli:jar:1.2:test
[INFO] commons-codec:commons-codec:jar:1.4:test
[INFO] commons-collections:commons-collections:jar:3.2.1:test
[INFO] commons-configuration:commons-configuration:jar:1.6:test
[INFO] commons-digester:commons-digester:jar:1.8:test
[INFO] commons-el:commons-el:jar:1.0:test
[INFO] commons-httpclient:commons-httpclient:jar:3.0.1:test
[INFO] commons-lang:commons-lang:jar:2.4:test
[INFO] commons-logging:commons-logging:jar:1.1.1:compile
[INFO] commons-net:commons-net:jar:1.4.1:test
[INFO] hsqldb:hsqldb:jar:1.8.0.10:test
[INFO] junit:junit:jar:4.10:test
[INFO] mysql:mysql-connector-java:jar:5.1.18:compile
[INFO] net.java.dev.jets3t:jets3t:jar:0.7.1:test
[INFO] net.sf.kosmosfs:kfs:jar:0.3:test
[INFO] org.apache.commons:commons-math:jar:2.1:test
[INFO] org.apache.ftpserver:ftplet-api:jar:1.0.0:test
[INFO] org.apache.ftpserver:ftpserver-core:jar:1.0.0:test
[INFO] org.apache.ftpserver:ftpserver-deprecated:jar:1.0.0-M2:test
[INFO] org.apache.hadoop:hadoop-core:jar:1.0.0:test
[INFO] org.apache.hadoop:hadoop-test:jar:1.0.0:test
[INFO] org.apache.mina:mina-core:jar:2.0.0-M5:test
[INFO] org.codehaus.jackson:jackson-core-asl:jar:1.0.1:test
[INFO] org.codehaus.jackson:jackson-mapper-asl:jar:1.0.1:test
[INFO] org.eclipse.jdt:core:jar:3.1.1:test
[INFO] org.hamcrest:hamcrest-core:jar:1.1:test
[INFO] org.liquibase:liquibase-core:jar:2.0.3:test
[INFO] org.liquibase.ext:liquibase-slf4j:jar:0.0.1:test
[INFO] org.mortbay.jetty:jetty:jar:6.1.26:test
[INFO] org.mortbay.jetty:jetty-util:jar:6.1.26:test
[INFO] org.mortbay.jetty:jsp-2.1:jar:6.1.14:test
[INFO] org.mortbay.jetty:jsp-api-2.1:jar:6.1.14:test
[INFO] org.mortbay.jetty:servlet-api:jar:2.5-20081211:test
[INFO] org.mortbay.jetty:servlet-api-2.5:jar:6.1.14:test
[INFO] org.slf4j:jcl-over-slf4j:jar:1.6.4:compile
[INFO] org.slf4j:log4j-over-slf4j:jar:1.6.4:compile
[INFO] org.slf4j:slf4j-api:jar:1.6.4:compile
[INFO] org.springframework:spring-aop:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-asm:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-beans:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-context:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-context-support:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-core:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-expression:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-jdbc:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-test:jar:3.1.1.RELEASE:test
[INFO] org.springframework:spring-tx:jar:3.1.1.RELEASE:compile
[INFO] org.springframework.data:spring-data-hadoop:jar:1.0.0.BUILD-SNAPSHOT:c
ompile
[INFO] oro:oro:jar:2.0.8:test
[INFO] tomcat:jasper-compiler:jar:5.5.12:test
[INFO] tomcat:jasper-runtime:jar:5.5.12:test
[INFO] xmlenc:xmlenc:jar:0.52:test
What you desire, is no longer valid for Maven 3 (this used to be valid for Maven 2). Maven 3 will attempt to obtain the nearest dependency, effectively ensuring that only one of the compile or test scoped dependency is used for both the compile and test phases.
In your case org.apache.hadoop:hadoop-core:1.0.0:test overrides org.apache.hadoop:hadoop-core:0.20.2-cdh3u2:compile and hence becomes the nearest dependency. You may see the following warning displayed by Maven when running the mvn dependency:list goal, that alludes to this being a problem in your project model:
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be
unique: org.apache.hadoop:hadoop-core:jar -> version 0.20.2-cdh3u2 vs 1.0.0 # line xyz, column xyz
To 'fix' this, it would be better to split your tests into a separate project whose project model can define a separate set of test dependencies.
Looks like a maven bug - or if not, something that is fishy enough I wouldn't trust the documentation if there were any.
In your case, I would probably:
upgrade maven and see if the issue is fixed in the latest m3
try repackaging one of the hadoop versions with another artifact id or group name. maven-shade-plugin, don't bother changing the package name, but just introduce something maven won't know is no different from org.apache.hadoop:hadoop-core
try moving the tests to a separate project downstream
start debugging maven and understand what's going on exactly (and then fall back on 1 or 2...)

Resources