[MNG-7368] Deeper merge logic for managed dependency declarations
- Dominant language
- Java
- Stars
- 5.3k
- Forks
- 3.1k
- Avg merge
- 20h 42m
- Merged PRs (30d)
- 297
Description
**[Hari Krishna Dara](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=haridsv)** opened **[MNG-7368](https://issues.apache.org/jira/browse/MNG-7368?redirect=false)** and commented
When inheriting `dependencyManagement` from parent, Maven's current merge logic is at the level of the list of `dependencies` which involves choosing the entire child's `dependency` declaration over that of the parent, i.e., no merging actually happens at the `dependency` level (it is all or nothing). This essentially makes it impossible to incrementally build the `{}dependencyManagement{`}. If the child projects have to repeat the entire `dependency` declaration, it defeats the purpose of sharing them in a parent-pom across multiple related projects. E.g., one common reason for managing them in parent is to centralize `version` for all dependencies at one place, but if the child must repeat the `version` to change anything in that dependency such as `scope` or `exclusion` rules, then there is no longer one central place.
I am attaching a very basic project structure (also attached as `{}depman-inheritance.zip{`}) to better demonstrate the issue.
Parent POM with a couple of managed dependencies:
```xml
4.0.0
depman-inheritance
parent
1.0-SNAPSHOT
parent
pom
junit
junit
4.11
test
org.apache.commons
commons-text
1.9
```
Project Root POM trying to change just the scope of one of the dependencies:
```xml
4.0.0
depman-inheritance
parent
1.0-SNAPSHOT
../parent/pom.xml
depman-inheritance
project
1.0-SNAPSHOT
project
pom
module
junit
junit
compile
```
Module POM simply using the dependencies:
```xml
4.0.0
depman-inheritance
project
1.0-SNAPSHOT
depman-inheritance
module
1.0-SNAPSHOT
module1
junit
junit
org.apache.commons
commons-text
```
With this, if we run any maven command in the project, I get the below error:
```
$ mvn dependency:tree
...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for junit:junit:jar is missing. @ line 17, column 17
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project depman-inheritance:module:1.0-SNAPSHOT (/Users/hdara/git/hdara/playground-mvn-project/depman-inheritance/project/module/pom.xml) has 1 error
[ERROR] 'dependencies.dependency.version' for junit:junit:jar is missing. @ line 17, column 17
...
```
I would like to propose that the support for deeper merging be added to Maven. There are however two aspects of this merging that I am not sure:
- Should/Can it be applied to all non-key fields?
- How to handle exclusion rules? Should they be overriding or be additive?
---
**Affects:** 3.8.1
**Attachments:**
- [depman-inheritance-1.zip](https://issues.apache.org/jira/secure/attachment/13037674/depman-inheritance-1.zip) (_2.36 kB_)
Contributor guide
Assessment
This issue has not been assessed yet.