openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.03k stars 300 forks source link

Change maven managed dependency classifier #4316

Closed Ferioney closed 2 weeks ago

Ferioney commented 2 weeks ago

What problem are you trying to solve?

Recipe Change Maven dependency classifier changes classifier only for dependency. In some case I want to change classifier for managed dependency as well.

Describe the situation before applying the recipe

pom.xml

<project>
...
    <dependencyManagement>
        <dependencies>
                 <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>${guava.version}</version>
                <classifier>jar</classifier>
        </dependencies>
    </dependencyManagement>
</project>

Describe the situation after applying the recipe

pom.xml

<project>
...
    <dependencyManagement>
        <dependencies>
                 <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>${guava.version}</version>
        </dependencies>
    </dependencyManagement>
</project>

Are you interested in [contributing this recipe to OpenRewrite]

It can be implemented by addition an additional check (isManagedDependencyTag(String groupId, String artifactId)) to the existing recipe: ChangeDependencyClassifier.isDependencyTag. For backward compatibility this check should be activated via property and disabled by default.

timtebeek commented 2 weeks ago

Hi @Ferioney ; thanks for the suggestion and early analysis as well; would love it if you're able to contribute such a change. An @Option seems like a fine solution; we might want to double check behavior when there's more than one managed dependency of the same groupId and artifactId, but we can discuss that on a PR.