How to decide the scope of transitive dependencies introduced by different dependencies?
up vote
3
down vote
favorite
Suppose my maven module M has the following dependencies:
M -> A(test scope) -> C(compile scope)
M -> B(compile scope) -> C(compile scope)
M depends on A and B with test and compile scope respectively. Both A and B depends on C with compile scope.
So my question is how maven decides the scope of C for M?
maven
add a comment |
up vote
3
down vote
favorite
Suppose my maven module M has the following dependencies:
M -> A(test scope) -> C(compile scope)
M -> B(compile scope) -> C(compile scope)
M depends on A and B with test and compile scope respectively. Both A and B depends on C with compile scope.
So my question is how maven decides the scope of C for M?
maven
1
Transitive scope resolution is explained in maven.apache.org/guides/introduction/…, so the first line would lead to a test dependency, the second one to a compile dependency. I guess that there is an order and compile wins over test, but I am not sure.
– JF Meier
21 hours ago
@JFMeier thanks for the input. I also thought compile scope should take precedence. But that's not the case in one of my project. So I wonder if there're certain rules that maven follows.
– Rui Li
21 hours ago
I would also be possible that this just decided by order. Maven has a rule to resolve dependency versions if several different exists (by depth, then by order), maybe this rule is also applied to scopes.
– JF Meier
20 hours ago
1
You can trymvn dependency:tree -Dverbose
to see if the test scoped dep is closer (less deep) in the tree. But I would also expect the compile scope to take precedence. Also make sure that you have the latest maven version and maven-dependency-plugin version, as there have been bug fixes in this area.
– gjoranv
17 hours ago
Thanks for your comments :) It turned out the issue with my project is that B is a shaded jar, and C is therefore removed from its pom. I think that's why I got a test scope of C for M.
– Rui Li
4 hours ago
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
Suppose my maven module M has the following dependencies:
M -> A(test scope) -> C(compile scope)
M -> B(compile scope) -> C(compile scope)
M depends on A and B with test and compile scope respectively. Both A and B depends on C with compile scope.
So my question is how maven decides the scope of C for M?
maven
Suppose my maven module M has the following dependencies:
M -> A(test scope) -> C(compile scope)
M -> B(compile scope) -> C(compile scope)
M depends on A and B with test and compile scope respectively. Both A and B depends on C with compile scope.
So my question is how maven decides the scope of C for M?
maven
maven
asked 22 hours ago
Rui Li
5125
5125
1
Transitive scope resolution is explained in maven.apache.org/guides/introduction/…, so the first line would lead to a test dependency, the second one to a compile dependency. I guess that there is an order and compile wins over test, but I am not sure.
– JF Meier
21 hours ago
@JFMeier thanks for the input. I also thought compile scope should take precedence. But that's not the case in one of my project. So I wonder if there're certain rules that maven follows.
– Rui Li
21 hours ago
I would also be possible that this just decided by order. Maven has a rule to resolve dependency versions if several different exists (by depth, then by order), maybe this rule is also applied to scopes.
– JF Meier
20 hours ago
1
You can trymvn dependency:tree -Dverbose
to see if the test scoped dep is closer (less deep) in the tree. But I would also expect the compile scope to take precedence. Also make sure that you have the latest maven version and maven-dependency-plugin version, as there have been bug fixes in this area.
– gjoranv
17 hours ago
Thanks for your comments :) It turned out the issue with my project is that B is a shaded jar, and C is therefore removed from its pom. I think that's why I got a test scope of C for M.
– Rui Li
4 hours ago
add a comment |
1
Transitive scope resolution is explained in maven.apache.org/guides/introduction/…, so the first line would lead to a test dependency, the second one to a compile dependency. I guess that there is an order and compile wins over test, but I am not sure.
– JF Meier
21 hours ago
@JFMeier thanks for the input. I also thought compile scope should take precedence. But that's not the case in one of my project. So I wonder if there're certain rules that maven follows.
– Rui Li
21 hours ago
I would also be possible that this just decided by order. Maven has a rule to resolve dependency versions if several different exists (by depth, then by order), maybe this rule is also applied to scopes.
– JF Meier
20 hours ago
1
You can trymvn dependency:tree -Dverbose
to see if the test scoped dep is closer (less deep) in the tree. But I would also expect the compile scope to take precedence. Also make sure that you have the latest maven version and maven-dependency-plugin version, as there have been bug fixes in this area.
– gjoranv
17 hours ago
Thanks for your comments :) It turned out the issue with my project is that B is a shaded jar, and C is therefore removed from its pom. I think that's why I got a test scope of C for M.
– Rui Li
4 hours ago
1
1
Transitive scope resolution is explained in maven.apache.org/guides/introduction/…, so the first line would lead to a test dependency, the second one to a compile dependency. I guess that there is an order and compile wins over test, but I am not sure.
– JF Meier
21 hours ago
Transitive scope resolution is explained in maven.apache.org/guides/introduction/…, so the first line would lead to a test dependency, the second one to a compile dependency. I guess that there is an order and compile wins over test, but I am not sure.
– JF Meier
21 hours ago
@JFMeier thanks for the input. I also thought compile scope should take precedence. But that's not the case in one of my project. So I wonder if there're certain rules that maven follows.
– Rui Li
21 hours ago
@JFMeier thanks for the input. I also thought compile scope should take precedence. But that's not the case in one of my project. So I wonder if there're certain rules that maven follows.
– Rui Li
21 hours ago
I would also be possible that this just decided by order. Maven has a rule to resolve dependency versions if several different exists (by depth, then by order), maybe this rule is also applied to scopes.
– JF Meier
20 hours ago
I would also be possible that this just decided by order. Maven has a rule to resolve dependency versions if several different exists (by depth, then by order), maybe this rule is also applied to scopes.
– JF Meier
20 hours ago
1
1
You can try
mvn dependency:tree -Dverbose
to see if the test scoped dep is closer (less deep) in the tree. But I would also expect the compile scope to take precedence. Also make sure that you have the latest maven version and maven-dependency-plugin version, as there have been bug fixes in this area.– gjoranv
17 hours ago
You can try
mvn dependency:tree -Dverbose
to see if the test scoped dep is closer (less deep) in the tree. But I would also expect the compile scope to take precedence. Also make sure that you have the latest maven version and maven-dependency-plugin version, as there have been bug fixes in this area.– gjoranv
17 hours ago
Thanks for your comments :) It turned out the issue with my project is that B is a shaded jar, and C is therefore removed from its pom. I think that's why I got a test scope of C for M.
– Rui Li
4 hours ago
Thanks for your comments :) It turned out the issue with my project is that B is a shaded jar, and C is therefore removed from its pom. I think that's why I got a test scope of C for M.
– Rui Li
4 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
-1
down vote
Short answer to your question is: C will be a compile scope dependency.
I tried to simulate your scenario with an example as below. Both dependencies (A, B) share same version of slf4j-api (C) library as compile scope dependency :
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>
mvn dependency:tree -Dverbose
[INFO] log-bench-mark:bench-mark:jar:1.0-SNAPSHOT
[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:test
[INFO] | +- ch.qos.logback:logback-core:jar:1.2.3:test
[INFO] | - (org.slf4j:slf4j-api:jar:1.7.25:compile - scope updated from test; omitted for duplicate)
[INFO] - org.slf4j:slf4j-log4j12:jar:1.7.25:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] - log4j:log4j:jar:1.2.17:compile
This does not answer the question. The question was: Is the scope of C test or compile?
– JF Meier
21 hours ago
@JFMeier, I published an update, hope it's clearer.
– hsnkhrmn
19 hours ago
"Maven applies a given dependency's scope to its transitive dependencies as well". This is not correct, there is a table in my link (my comment to the question) that shows how transitive dependency scopes are chosen.
– JF Meier
18 hours ago
@JFMeier Take a look on dependency:tree plugin output: "scope updated from test; omitted for duplicate" message. Which means maven first assign scope as 'test' then due to conflict, grants it the 'compile' scope. This is what I'm writing in the rest of my sentence which you quoted from.
– hsnkhrmn
17 hours ago
1
Your sentence is not generally true. E.g. if a compile dependency has a provided dependency, that provided dependency is dropped. Maven does not always apply the scope to all transitive dependencies.
– JF Meier
17 hours ago
|
show 2 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
-1
down vote
Short answer to your question is: C will be a compile scope dependency.
I tried to simulate your scenario with an example as below. Both dependencies (A, B) share same version of slf4j-api (C) library as compile scope dependency :
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>
mvn dependency:tree -Dverbose
[INFO] log-bench-mark:bench-mark:jar:1.0-SNAPSHOT
[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:test
[INFO] | +- ch.qos.logback:logback-core:jar:1.2.3:test
[INFO] | - (org.slf4j:slf4j-api:jar:1.7.25:compile - scope updated from test; omitted for duplicate)
[INFO] - org.slf4j:slf4j-log4j12:jar:1.7.25:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] - log4j:log4j:jar:1.2.17:compile
This does not answer the question. The question was: Is the scope of C test or compile?
– JF Meier
21 hours ago
@JFMeier, I published an update, hope it's clearer.
– hsnkhrmn
19 hours ago
"Maven applies a given dependency's scope to its transitive dependencies as well". This is not correct, there is a table in my link (my comment to the question) that shows how transitive dependency scopes are chosen.
– JF Meier
18 hours ago
@JFMeier Take a look on dependency:tree plugin output: "scope updated from test; omitted for duplicate" message. Which means maven first assign scope as 'test' then due to conflict, grants it the 'compile' scope. This is what I'm writing in the rest of my sentence which you quoted from.
– hsnkhrmn
17 hours ago
1
Your sentence is not generally true. E.g. if a compile dependency has a provided dependency, that provided dependency is dropped. Maven does not always apply the scope to all transitive dependencies.
– JF Meier
17 hours ago
|
show 2 more comments
up vote
-1
down vote
Short answer to your question is: C will be a compile scope dependency.
I tried to simulate your scenario with an example as below. Both dependencies (A, B) share same version of slf4j-api (C) library as compile scope dependency :
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>
mvn dependency:tree -Dverbose
[INFO] log-bench-mark:bench-mark:jar:1.0-SNAPSHOT
[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:test
[INFO] | +- ch.qos.logback:logback-core:jar:1.2.3:test
[INFO] | - (org.slf4j:slf4j-api:jar:1.7.25:compile - scope updated from test; omitted for duplicate)
[INFO] - org.slf4j:slf4j-log4j12:jar:1.7.25:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] - log4j:log4j:jar:1.2.17:compile
This does not answer the question. The question was: Is the scope of C test or compile?
– JF Meier
21 hours ago
@JFMeier, I published an update, hope it's clearer.
– hsnkhrmn
19 hours ago
"Maven applies a given dependency's scope to its transitive dependencies as well". This is not correct, there is a table in my link (my comment to the question) that shows how transitive dependency scopes are chosen.
– JF Meier
18 hours ago
@JFMeier Take a look on dependency:tree plugin output: "scope updated from test; omitted for duplicate" message. Which means maven first assign scope as 'test' then due to conflict, grants it the 'compile' scope. This is what I'm writing in the rest of my sentence which you quoted from.
– hsnkhrmn
17 hours ago
1
Your sentence is not generally true. E.g. if a compile dependency has a provided dependency, that provided dependency is dropped. Maven does not always apply the scope to all transitive dependencies.
– JF Meier
17 hours ago
|
show 2 more comments
up vote
-1
down vote
up vote
-1
down vote
Short answer to your question is: C will be a compile scope dependency.
I tried to simulate your scenario with an example as below. Both dependencies (A, B) share same version of slf4j-api (C) library as compile scope dependency :
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>
mvn dependency:tree -Dverbose
[INFO] log-bench-mark:bench-mark:jar:1.0-SNAPSHOT
[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:test
[INFO] | +- ch.qos.logback:logback-core:jar:1.2.3:test
[INFO] | - (org.slf4j:slf4j-api:jar:1.7.25:compile - scope updated from test; omitted for duplicate)
[INFO] - org.slf4j:slf4j-log4j12:jar:1.7.25:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] - log4j:log4j:jar:1.2.17:compile
Short answer to your question is: C will be a compile scope dependency.
I tried to simulate your scenario with an example as below. Both dependencies (A, B) share same version of slf4j-api (C) library as compile scope dependency :
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>
mvn dependency:tree -Dverbose
[INFO] log-bench-mark:bench-mark:jar:1.0-SNAPSHOT
[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:test
[INFO] | +- ch.qos.logback:logback-core:jar:1.2.3:test
[INFO] | - (org.slf4j:slf4j-api:jar:1.7.25:compile - scope updated from test; omitted for duplicate)
[INFO] - org.slf4j:slf4j-log4j12:jar:1.7.25:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] - log4j:log4j:jar:1.2.17:compile
edited 14 hours ago
answered 21 hours ago
hsnkhrmn
658415
658415
This does not answer the question. The question was: Is the scope of C test or compile?
– JF Meier
21 hours ago
@JFMeier, I published an update, hope it's clearer.
– hsnkhrmn
19 hours ago
"Maven applies a given dependency's scope to its transitive dependencies as well". This is not correct, there is a table in my link (my comment to the question) that shows how transitive dependency scopes are chosen.
– JF Meier
18 hours ago
@JFMeier Take a look on dependency:tree plugin output: "scope updated from test; omitted for duplicate" message. Which means maven first assign scope as 'test' then due to conflict, grants it the 'compile' scope. This is what I'm writing in the rest of my sentence which you quoted from.
– hsnkhrmn
17 hours ago
1
Your sentence is not generally true. E.g. if a compile dependency has a provided dependency, that provided dependency is dropped. Maven does not always apply the scope to all transitive dependencies.
– JF Meier
17 hours ago
|
show 2 more comments
This does not answer the question. The question was: Is the scope of C test or compile?
– JF Meier
21 hours ago
@JFMeier, I published an update, hope it's clearer.
– hsnkhrmn
19 hours ago
"Maven applies a given dependency's scope to its transitive dependencies as well". This is not correct, there is a table in my link (my comment to the question) that shows how transitive dependency scopes are chosen.
– JF Meier
18 hours ago
@JFMeier Take a look on dependency:tree plugin output: "scope updated from test; omitted for duplicate" message. Which means maven first assign scope as 'test' then due to conflict, grants it the 'compile' scope. This is what I'm writing in the rest of my sentence which you quoted from.
– hsnkhrmn
17 hours ago
1
Your sentence is not generally true. E.g. if a compile dependency has a provided dependency, that provided dependency is dropped. Maven does not always apply the scope to all transitive dependencies.
– JF Meier
17 hours ago
This does not answer the question. The question was: Is the scope of C test or compile?
– JF Meier
21 hours ago
This does not answer the question. The question was: Is the scope of C test or compile?
– JF Meier
21 hours ago
@JFMeier, I published an update, hope it's clearer.
– hsnkhrmn
19 hours ago
@JFMeier, I published an update, hope it's clearer.
– hsnkhrmn
19 hours ago
"Maven applies a given dependency's scope to its transitive dependencies as well". This is not correct, there is a table in my link (my comment to the question) that shows how transitive dependency scopes are chosen.
– JF Meier
18 hours ago
"Maven applies a given dependency's scope to its transitive dependencies as well". This is not correct, there is a table in my link (my comment to the question) that shows how transitive dependency scopes are chosen.
– JF Meier
18 hours ago
@JFMeier Take a look on dependency:tree plugin output: "scope updated from test; omitted for duplicate" message. Which means maven first assign scope as 'test' then due to conflict, grants it the 'compile' scope. This is what I'm writing in the rest of my sentence which you quoted from.
– hsnkhrmn
17 hours ago
@JFMeier Take a look on dependency:tree plugin output: "scope updated from test; omitted for duplicate" message. Which means maven first assign scope as 'test' then due to conflict, grants it the 'compile' scope. This is what I'm writing in the rest of my sentence which you quoted from.
– hsnkhrmn
17 hours ago
1
1
Your sentence is not generally true. E.g. if a compile dependency has a provided dependency, that provided dependency is dropped. Maven does not always apply the scope to all transitive dependencies.
– JF Meier
17 hours ago
Your sentence is not generally true. E.g. if a compile dependency has a provided dependency, that provided dependency is dropped. Maven does not always apply the scope to all transitive dependencies.
– JF Meier
17 hours ago
|
show 2 more comments
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408104%2fhow-to-decide-the-scope-of-transitive-dependencies-introduced-by-different-depen%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Transitive scope resolution is explained in maven.apache.org/guides/introduction/…, so the first line would lead to a test dependency, the second one to a compile dependency. I guess that there is an order and compile wins over test, but I am not sure.
– JF Meier
21 hours ago
@JFMeier thanks for the input. I also thought compile scope should take precedence. But that's not the case in one of my project. So I wonder if there're certain rules that maven follows.
– Rui Li
21 hours ago
I would also be possible that this just decided by order. Maven has a rule to resolve dependency versions if several different exists (by depth, then by order), maybe this rule is also applied to scopes.
– JF Meier
20 hours ago
1
You can try
mvn dependency:tree -Dverbose
to see if the test scoped dep is closer (less deep) in the tree. But I would also expect the compile scope to take precedence. Also make sure that you have the latest maven version and maven-dependency-plugin version, as there have been bug fixes in this area.– gjoranv
17 hours ago
Thanks for your comments :) It turned out the issue with my project is that B is a shaded jar, and C is therefore removed from its pom. I think that's why I got a test scope of C for M.
– Rui Li
4 hours ago