Reputation: 690
I referred to this thread differences between dependencymanagement and dependencies in maven but this question is specific.
Parent POM:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.company.rtdp.rtds</groupId>
<artifactId>rtds-client</artifactId>
<version>${rtdp.rtds-client.version}</version>
<!-- SCENARIO 1 : Either give scope here in parent POM -->
<!-- <scope>provided</scope> -->
</dependency>
</dependencies>
</dependencyManagement>
<rtdp.rtds-client.version>1.4.6</rtdp.rtds-client.version>
Child POM:
<dependencies>
<!-- SCENARIO 2
<dependency>
<groupId>com.company.rtdp.rtds</groupId>
<artifactId>realtimedataserv-client</artifactId>
<version>1.4.6</version>
<scope>provided</scope>
</dependency>
-->
<dependency>
<groupId>com.company.idi</groupId>
<artifactId>idi-persistence</artifactId>
<version>3.3</version>
<!-- has a dependency of com.company.rtdp.rtds:rtds-client:jar:1.4.6:compile -->
</dependency>
</dependencies>
<!-- SCENARIO 1: OR give scope here in child POM
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.company.rtdp.rtds</groupId>
<artifactId>rtds-client</artifactId>
<version>1.4.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
-->
rtds-client
is a transitive dependency of many artifacts out of which idi-persistence
is one of them. I want to exclude 1.4.6 in all of the transitive dependencies since I am going to include a different artifact rtds-framework-client
(different artifact name) explicitly which is backward compatible to 1.4.6 with <dependency>
in child POM.
If have to use <exclusion>
I have to explicitly give this in all the dependencies. So, I have decided to go <scope>provided</scope>
way.
Known info of Maven based on which my question follows:
If I include the following in child POM (with a version higher than 1.4.6, then rtds-client
in all transitive dependencies gets shifted to 1.8. I could see this from 'Dependency Hierarchy'
of Eclipse which says 'omitted for conflict with 1.8' [compile]
) which means it considers/overrides the version specified in child POM (idi-persistence
now gets 1.8).
<dependency>
<groupId>com.company.rtdp.rtds</groupId>
<artifactId>rtds-client</artifactId>
<version>1.8</version>
</dependency>
Question:
If I include the following in child POM without <dependencyManagement>
around:
<dependency>
<groupId>com.company.rtdp.rtds</groupId>
<artifactId>rtds-client</artifactId>
<version>1.4.6</version>
<scope>provided<scope>
</dependency>
None of the rtds-client
which comes as transitive dependency considers provided
scope whereas I mention the same in a <dependencyManagement>
tag either in parent or child POM, provided
scope gets applied.
Why version
gets affected but not scope
given inside <dependency>
tag and for scope
(for this kind of use case) I have to go for <dependencyManagement>
?
Say if this is allowed, what problem it would lead us into ?
EDIT:
i) <scope>provided
with <dependencyManagement>/<dependencies>/<dependency>
either in child or parent POM:
Though the longer path is omitted, it says [provided]
,here.
[INFO] +- com.company.idi:idi-persistence:jar:3.3:compile
[INFO] | +- com.company.rtdp.rtds:realtimedataserv-client:jar:1.4.6:provided
ii) <scope>provided
with direct <dependencies>/<dependency>
in child POM without <dependencyManagement>
around :
Though the longer path is omitted, it does not say provided
and just compile
alone.
[INFO] --- maven-dependency-plugin:2.3:tree (default-cli) @ read-rest-service ---
[INFO] +- com.company.rtdp.rtds:realtimedataserv-client:jar:1.4.6:provided (scope not updated to compile)
Upvotes: 3
Views: 2177
Reputation: 14762
I can't comprehend your <scope>provided
in <dependencyManagement>
vs. <dependency
.
If I declare a child POM, with no dependency[Management]
in the parent whatsoever, like:
<project ...>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>igb.so</groupId>
<artifactId>SO-44987444-parent</artifactId>
<relativePath>../SO-44987444-parent</relativePath>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>SO-44987444-child</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.1</version>
<!-- has a dependency of org.apache.commons:commons-lang3:jar:3.5:compile -->
</dependency>
</dependencies>
</project>
the dependency:tree
looks like:
[INFO] ------------------------------------------------------------------------
[INFO] Building SO-44987444-child 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ SO-44987444-child ---
[INFO] igb.so:SO-44987444-child:jar:0.0.1-SNAPSHOT
[INFO] \- org.apache.commons:commons-text:jar:1.1:compile
[INFO] \- org.apache.commons:commons-lang3:jar:3.5:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
If I add commons-lang3
as direct dependency with <scope>provided
:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
<scope>provided</scope>
</dependency>
the dependency:tree
looks like:
[INFO] ------------------------------------------------------------------------
[INFO] Building SO-44987444-child 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ SO-44987444-child ---
[INFO] igb.so:SO-44987444-child:jar:0.0.1-SNAPSHOT
[INFO] +- org.apache.commons:commons-text:jar:1.1:compile
[INFO] \- org.apache.commons:commons-lang3:jar:3.5:provided
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Even if I add to the parent POM:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
</dependencies>
</dependencyManagement>
the dependency:tree
results aren't any different.
Upvotes: 2