Skip to content

Set <relativePath/> in dependency-reduced-pom.xml to avoid false parent cycle in Maven 4 #813

@gnodet

Description

@gnodet

Summary

The dependency-reduced-pom.xml generated by the shade plugin preserves the original POM's <parent> element without setting an explicit <relativePath/>. 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:

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 <relativePath/> 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 <relativePath/> (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 <relativePath/> 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions