rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

UseParentInference - use parent inference if relativePath is not present

Open philippe-granet opened this issue 2 months ago • 2 comments

What is the smallest, simplest way to reproduce the problem?

Running UseParentInference on a project with this parent pom:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>parent</artifactId>
    <version>1.0.0</version>
    <packaging>pom</packaging>
</project>

and this child pom:

<project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.example</groupId>
        <artifactId>parent</artifactId>
        <version>1.0.0</version>
    </parent>
    <artifactId>child</artifactId>
</project>

What did you expect to see?

In child pom:

<project>
    <modelVersion>4.0.0</modelVersion>
    <parent/>
    <artifactId>child</artifactId>
</project>

What did you see instead?

No modification

I think this recipe should also use parent inference when all these conditions are met:

  • relativePath is not present (which defaults to "..")
  • child groupId/version match parent
  • the parent is part of the same reactor (multi-module project) vs. an external parent POM by checking if the parent exists in the project poms.

Maven give a mvnup command to upgrade, here the implementation in Maven core to use parent inference: https://github.com/apache/maven/blob/39bd4b78a22afdf4b6c0077ef923d24e0de4b306/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/InferenceStrategy.java#L383

philippe-granet avatar Oct 30 '25 23:10 philippe-granet

Sorry for the bug issue, it's more a feature request 😊

philippe-granet avatar Oct 30 '25 23:10 philippe-granet

Thanks for the helpful sample! Would indeed make for a nice addition to that recipe; for now that had just targeted the simplest case, but it should be straightforward to extend if we take the presence of the parent into account as well.

timtebeek avatar Nov 01 '25 12:11 timtebeek