openrewrite / rewrite

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

org.openrewrite.maven.cleanup.ExplicitPluginVersion #4495

Open HelloDhero opened 2 weeks ago

HelloDhero commented 2 weeks ago

when plugin is locked version by pluginManagement , it is no need to add ''

timtebeek commented 2 weeks ago

Hi @HelloDhero ; Could you explain in what circumstance you saw this issue? We normally have a format for that when you open a new issue. I've tried to replicate your issue but have so far failed, as these two tests pass:

https://github.com/openrewrite/rewrite/blob/769f6de46e2e3d711c495feb82e7e5e0f2d889c9/rewrite-maven/src/test/java/org/openrewrite/maven/cleanup/ExplicitPluginVersionTest.java#L114-L140

@Test
@Issue("https://github.com/openrewrite/rewrite/issues/4495")
void shouldNotOverrideManagedVersion() {
    rewriteRun(
      pomXml(
        """
          <project>
            <groupId>com.mycompany.app</groupId>
            <artifactId>my-app</artifactId>
            <version>1</version>
            <build>
              <pluginManagement>
                <plugins>
                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>>
                    <version>3.8.0</version>
                  </plugin>
                </plugins>
              </pluginManagement>
              <plugins>
                <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                  </configuration>
                </plugin>
              </plugins>
            </build>
          </project>
          """
      )
    );
}