openrewrite / rewrite

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

Maven: UpgradePluginVersion does not work for plugins in pluginManagement #4137

Open smurf667 opened 2 months ago

smurf667 commented 2 months ago

What version of OpenRewrite are you using?

I am using org.openrewrite.maven:rewrite-maven-plugin:5.28.0

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project. I am using the following pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-
v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>demo</groupId>
    <artifactId>demo</artifactId>
    <version>0.1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <info.version>3.4.5</info.version>
    </properties>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                    <version>${info.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.sonarsource.scanner.maven</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                    <version>3.10.0.2594</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <!-- put the plugin here and the update will be performed...
<plugin><groupId>org.sonarsource.scanner.maven</groupId><artifactId>sonar-maven-plugin</artifactId><version>3.10.0.2594</version></plugin>
-->
        </plugins>
    </build>
</project>

As a sibling to pom.xml the following rewrite.yml exists:

---
type: specs.openrewrite.org/v1beta/recipe
name: demo
displayName: Upgrade Maven plugin versions
recipeList:
  - org.openrewrite.maven.UpgradePluginVersion:
      groupId: org.apache.maven.plugins
      artifactId: maven-project-info-reports-plugin
      newVersion: latest.release
  - org.openrewrite.maven.UpgradePluginVersion:
      groupId: org.sonarsource.scanner.maven
      artifactId: sonar-maven-plugin
      newVersion: latest.release

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

See the setup above; I am running mvn org.openrewrite.maven:rewrite-maven-plugin:5.28.0:run -Drewrite.activeRecipes=demo

What did you expect to see?

I expected the recipe to update both the property and the version of the plugins declared in <pluginManagement/>.

What did you see instead?

No modification occurred, the plugins are not updated.

Note when I declare a plugin in <plugins/> instead, an update is performed. I am using <pluginManagement/> because my ultimate use would be also in multi-module projects.

What is the full stack trace of any errors you encountered?

No errors, no stracktrace, just no expected updated plugin versions.

Are you interested in contributing a fix to OpenRewrite?

Sorry, I can't.

timtebeek commented 2 months ago

Thanks for the suggestion! We recently made a similar change for dependencies and dependency management. Think we could do the same here, as indeed it would be surprising not to see any such changes.