You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Jamal B <jm...@gmail.com> on 2013/06/03 19:20:50 UTC
Transitive Dependency Question
Hello, I have a question about transitive dependencies. According to the
pom documentation here: http://maven.apache.org/pom.html#Dependencies
project dependencies marked with test scope are not transitive. I assumed
that this also applied to it's dependencies, so my question is if I declare
a dependency on a project at test scope, that project's dependencies should
all be included at test scope. For example, given the following project(s)
Project test-utils defines a junit dependency like such:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
Project application defines a dependency on test-utils with a scope of test
like such
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>test-utils</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
Now running mvn clean dependency:tree shows that the junit dependency is
being passed to the application project at compile scope which is not
expected.
[INFO] --- maven-dependency-plugin:2.7:tree (default-cli) @ application ---
[INFO] org.sandbox:application:war:1.0.0-SNAPSHOT
....
[INFO] \- org.sandbox:test-utils:jar:1.0.0-SNAPSHOT:test
[INFO] +- junit:junit:jar:4.8.2:compile
[INFO] +- org.mockito:mockito-all:jar:1.8.5:test
[INFO] +- com.h2database:h2:jar:1.3.165:test
[INFO] \- log4j:log4j:jar:1.2.16:test
Is this a bug or was my interpretation of the transitive dependency logic
incorrect?
Thank you for your time.
Re: Transitive Dependency Question
Posted by Jamal B <jm...@gmail.com>.
Hi, thanks for your response.
Running dependency:list shows also shows that junit is at compile scope
which I expected to be at test scope.
[INFO] --- maven-dependency-plugin:2.7:list (default-cli) @ application ---
[INFO]
[INFO] The following files have been resolved:
....
[INFO] junit:junit:jar:4.8.2:compile
So is it a correct statement that the base scope of a dependency is fixed
regardless of the declared scope of the outer dependency? This appears to
be the behavior, but I am not sure that this is correct.
On Mon, Jun 3, 2013 at 1:53 PM, Baptiste MATHUS <ml...@batmat.net> wrote:
> Hi,
> Tree is showing the tree. So it seems correct at first sight. Its showing
> you the dependency beetween your test-utils of the project and junit which
> is in fact scope compile.
>
> What you seem to actually want to have is the resolved list of dependencies
> for your application project.
> That goal is called dependency:list.
>
> Hope this helps.
>
> Cheers
>
> -- Baptiste
> Le 3 juin 2013 19:21, "Jamal B" <jm...@gmail.com> a écrit :
>
> > Hello, I have a question about transitive dependencies. According to the
> > pom documentation here: http://maven.apache.org/pom.html#Dependencies
> >
> > project dependencies marked with test scope are not transitive. I
> assumed
> > that this also applied to it's dependencies, so my question is if I
> declare
> > a dependency on a project at test scope, that project's dependencies
> should
> > all be included at test scope. For example, given the following
> project(s)
> >
> > Project test-utils defines a junit dependency like such:
> >
> > <dependency>
> > <groupId>junit</groupId>
> > <artifactId>junit</artifactId>
> > </dependency>
> >
> > Project application defines a dependency on test-utils with a scope of
> test
> > like such
> > <dependency>
> > <groupId>${project.groupId}</groupId>
> > <artifactId>test-utils</artifactId>
> > <version>${project.version}</version>
> > <scope>test</scope>
> > </dependency>
> >
> > Now running mvn clean dependency:tree shows that the junit dependency is
> > being passed to the application project at compile scope which is not
> > expected.
> >
> > [INFO] --- maven-dependency-plugin:2.7:tree (default-cli) @ application
> ---
> > [INFO] org.sandbox:application:war:1.0.0-SNAPSHOT
> > ....
> > [INFO] \- org.sandbox:test-utils:jar:1.0.0-SNAPSHOT:test
> > [INFO] +- junit:junit:jar:4.8.2:compile
> > [INFO] +- org.mockito:mockito-all:jar:1.8.5:test
> > [INFO] +- com.h2database:h2:jar:1.3.165:test
> > [INFO] \- log4j:log4j:jar:1.2.16:test
> >
> >
> > Is this a bug or was my interpretation of the transitive dependency logic
> > incorrect?
> >
> > Thank you for your time.
> >
>
Re: Transitive Dependency Question
Posted by Baptiste MATHUS <ml...@batmat.net>.
Hi,
Tree is showing the tree. So it seems correct at first sight. Its showing
you the dependency beetween your test-utils of the project and junit which
is in fact scope compile.
What you seem to actually want to have is the resolved list of dependencies
for your application project.
That goal is called dependency:list.
Hope this helps.
Cheers
-- Baptiste
Le 3 juin 2013 19:21, "Jamal B" <jm...@gmail.com> a écrit :
> Hello, I have a question about transitive dependencies. According to the
> pom documentation here: http://maven.apache.org/pom.html#Dependencies
>
> project dependencies marked with test scope are not transitive. I assumed
> that this also applied to it's dependencies, so my question is if I declare
> a dependency on a project at test scope, that project's dependencies should
> all be included at test scope. For example, given the following project(s)
>
> Project test-utils defines a junit dependency like such:
>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> </dependency>
>
> Project application defines a dependency on test-utils with a scope of test
> like such
> <dependency>
> <groupId>${project.groupId}</groupId>
> <artifactId>test-utils</artifactId>
> <version>${project.version}</version>
> <scope>test</scope>
> </dependency>
>
> Now running mvn clean dependency:tree shows that the junit dependency is
> being passed to the application project at compile scope which is not
> expected.
>
> [INFO] --- maven-dependency-plugin:2.7:tree (default-cli) @ application ---
> [INFO] org.sandbox:application:war:1.0.0-SNAPSHOT
> ....
> [INFO] \- org.sandbox:test-utils:jar:1.0.0-SNAPSHOT:test
> [INFO] +- junit:junit:jar:4.8.2:compile
> [INFO] +- org.mockito:mockito-all:jar:1.8.5:test
> [INFO] +- com.h2database:h2:jar:1.3.165:test
> [INFO] \- log4j:log4j:jar:1.2.16:test
>
>
> Is this a bug or was my interpretation of the transitive dependency logic
> incorrect?
>
> Thank you for your time.
>
Re: Transitive Dependency Question
Posted by Jörg Schaible <Jo...@scalaris.com>.
Hi Jamal,
Jamal B wrote:
> Interesting....
>
> Taking your suggestion, it looks like it is coming in from another compile
> dependency, and was "promoted" to compile.
>
> [INFO] +- org.apache.maven.shared:maven-shared-jar:jar:1.1:compile
> [INFO] | +- org.codehaus.plexus:plexus-digest:jar:1.0:compile
> [INFO] | | \-
> org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-8:compile
> [INFO] | | +- junit:junit:jar:3.8.1:compile
>
> Is there a way to prevent this from happening without having to add
> exclude stanzas across projects where this is happening?
You can control this with a dependencyManagement section of a shared parent.
Just define there junit:junit:<version> and the scope.
The annoying part is nevertheless that the situation is no longer obvious in
M3. Try this in M2 and you'll see that the dependency makes much more sense.
Since the same plugin produces different output, I blame the new Aether
backend here which favors now the "nearest" occurrence without taking the
inherited scope into account. While this behavior has no impact on the
resulting class path, it hides dependency problems like the one, you have
encountered here.
- Jörg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Transitive Dependency Question
Posted by Jamal B <jm...@gmail.com>.
Interesting....
Taking your suggestion, it looks like it is coming in from another compile
dependency, and was "promoted" to compile.
[INFO] +- org.apache.maven.shared:maven-shared-jar:jar:1.1:compile
[INFO] | +- org.codehaus.plexus:plexus-digest:jar:1.0:compile
[INFO] | | \-
org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-8:compile
[INFO] | | +- junit:junit:jar:3.8.1:compile
Is there a way to prevent this from happening without having to add exclude
stanzas across projects where this is happening?
On Mon, Jun 3, 2013 at 7:56 PM, Jörg Schaible <jo...@gmx.de> wrote:
> Hi Jamal,
>
> Jamal B wrote:
>
> > Hello, I have a question about transitive dependencies. According to the
> > pom documentation here: http://maven.apache.org/pom.html#Dependencies
> >
> > project dependencies marked with test scope are not transitive. I
> assumed
> > that this also applied to it's dependencies, so my question is if I
> > declare a dependency on a project at test scope, that project's
> > dependencies should
> > all be included at test scope. For example, given the following
> > project(s)
> >
> > Project test-utils defines a junit dependency like such:
> >
> > <dependency>
> > <groupId>junit</groupId>
> > <artifactId>junit</artifactId>
> > </dependency>
> >
> > Project application defines a dependency on test-utils with a scope of
> > test like such
> > <dependency>
> > <groupId>${project.groupId}</groupId>
> > <artifactId>test-utils</artifactId>
> > <version>${project.version}</version>
> > <scope>test</scope>
> > </dependency>
> >
> > Now running mvn clean dependency:tree shows that the junit dependency is
> > being passed to the application project at compile scope which is not
> > expected.
> >
> > [INFO] --- maven-dependency-plugin:2.7:tree (default-cli) @ application
> > [--- INFO] org.sandbox:application:war:1.0.0-SNAPSHOT
> > ....
> > [INFO] \- org.sandbox:test-utils:jar:1.0.0-SNAPSHOT:test
> > [INFO] +- junit:junit:jar:4.8.2:compile
> > [INFO] +- org.mockito:mockito-all:jar:1.8.5:test
> > [INFO] +- com.h2database:h2:jar:1.3.165:test
> > [INFO] \- log4j:log4j:jar:1.2.16:test
> >
> >
> > Is this a bug or was my interpretation of the transitive dependency logic
> > incorrect?
> >
> > Thank you for your time.
>
> Actually I was fooled by such an output with M3 in one of my projects at
> first sight also.
>
> So, please make a test: Comment out the org.sandbox:test-utils in your POM
> and print the tree again. I am quite sure that you will see that
> junit:junit
> is now introduced by a different dependency that is not of test scope. What
> you see above is only the result of the dependency resolver. It detected
> that it already has a junit:junit in its transitive deps in compile scope
> (maybe even in a different version), but the "nearest" path to junit was as
> direct child of org.sandbox:test-utils. Therefor it was "promoted" to
> compile scope in this place, but the overall result of the compilation
> classpath is still OK, it is only the displayed tree that is somewhat
> inconsistent (compared to M2).
>
> - Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
Re: Transitive Dependency Question
Posted by Jörg Schaible <jo...@gmx.de>.
Hi Jamal,
Jamal B wrote:
> Hello, I have a question about transitive dependencies. According to the
> pom documentation here: http://maven.apache.org/pom.html#Dependencies
>
> project dependencies marked with test scope are not transitive. I assumed
> that this also applied to it's dependencies, so my question is if I
> declare a dependency on a project at test scope, that project's
> dependencies should
> all be included at test scope. For example, given the following
> project(s)
>
> Project test-utils defines a junit dependency like such:
>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> </dependency>
>
> Project application defines a dependency on test-utils with a scope of
> test like such
> <dependency>
> <groupId>${project.groupId}</groupId>
> <artifactId>test-utils</artifactId>
> <version>${project.version}</version>
> <scope>test</scope>
> </dependency>
>
> Now running mvn clean dependency:tree shows that the junit dependency is
> being passed to the application project at compile scope which is not
> expected.
>
> [INFO] --- maven-dependency-plugin:2.7:tree (default-cli) @ application
> [--- INFO] org.sandbox:application:war:1.0.0-SNAPSHOT
> ....
> [INFO] \- org.sandbox:test-utils:jar:1.0.0-SNAPSHOT:test
> [INFO] +- junit:junit:jar:4.8.2:compile
> [INFO] +- org.mockito:mockito-all:jar:1.8.5:test
> [INFO] +- com.h2database:h2:jar:1.3.165:test
> [INFO] \- log4j:log4j:jar:1.2.16:test
>
>
> Is this a bug or was my interpretation of the transitive dependency logic
> incorrect?
>
> Thank you for your time.
Actually I was fooled by such an output with M3 in one of my projects at
first sight also.
So, please make a test: Comment out the org.sandbox:test-utils in your POM
and print the tree again. I am quite sure that you will see that junit:junit
is now introduced by a different dependency that is not of test scope. What
you see above is only the result of the dependency resolver. It detected
that it already has a junit:junit in its transitive deps in compile scope
(maybe even in a different version), but the "nearest" path to junit was as
direct child of org.sandbox:test-utils. Therefor it was "promoted" to
compile scope in this place, but the overall result of the compilation
classpath is still OK, it is only the displayed tree that is somewhat
inconsistent (compared to M2).
- Jörg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org