apache / apache/maven-shade-plugin
Set <relativePath/> in dependency-reduced-pom.xml to avoid false parent cycle in Maven 4
- Dominant language
- Java
- Stars
- 188
- Forks
- 103
- Avg merge
- 16h 39m
- Merged PRs (30d)
- 4
Description
## Summary
The `dependency-reduced-pom.xml` generated by the shade plugin preserves the original POM's `` element without setting an explicit ``. In Maven 4, this can cause a false parent cycle detection error when the default relative path `..` resolves to a POM with a different GA that shares the same parent reference.
## Reproduction
Build any project using the shade plugin with a parent POM, e.g., [apache/maven-doxia-converter](https://github.com/apache/maven-doxia-converter):
```
mvn package -DskipTests
```
With Maven 4, this fails with:
```
[FATAL] The parents form a cycle: org.apache.maven.doxia:doxia-tools:43 ->
/path/to/project/pom.xml -> org.apache.maven.doxia:doxia-tools:43
for project [inherited]:doxia-converter:jar:1.4-SNAPSHOT
at /path/to/project/dependency-reduced-pom.xml
```
## Root cause
The generated `dependency-reduced-pom.xml` inherits the parent element as-is from the original POM. Since no `` is set, Maven defaults to `..`, which may resolve to a POM that is not the actual parent. Maven 4's stricter model builder detects this as a cycle when the resolved POM shares the same parent reference.
## Proposed fix
When writing the `dependency-reduced-pom.xml`, set `` (empty) in the parent element to explicitly disable local parent resolution. The parent should always be resolved from the repository for generated POMs.
## Workaround
A fix has been submitted for the Maven 4 model builder (apache/maven#12078, apache/maven#12079) that detects the GA mismatch early and avoids the false cycle. However, setting `` in the generated POM is the correct long-term fix on the plugin side.
## Environment
- Maven: 4.0.0-rc-2+
- maven-shade-plugin: 3.6.0 / 3.6.1
Related: apache/maven#12074
_Claude Code on behalf of Guillaume Nodet_
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the code that writes dependency-reduced-pom.xml and inspect how the original parent element is copied. Reproduce the issue with Maven 4 using the maven-doxia-converter example and mvn package -DskipTests; done means the generated parent contains an empty relativePath and the false cycle no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100