How to decide the scope of transitive dependencies introduced by different dependencies?











up vote
3
down vote

favorite
1












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?










share|improve this question


















  • 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















up vote
3
down vote

favorite
1












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?










share|improve this question


















  • 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













up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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














  • 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








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












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





share|improve this answer























  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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





share|improve this answer























  • 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















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





share|improve this answer























  • 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













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





share|improve this answer














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






share|improve this answer














share|improve this answer



share|improve this answer








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


















  • 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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks