rewrite-migrate-java icon indicating copy to clipboard operation
rewrite-migrate-java copied to clipboard

UpgradeJavaVersion leaves behind stale unused properties

Open sushmitha-malae opened this issue 1 year ago • 2 comments

What version of OpenRewrite are you using?

I am using

  • rewrite Maven plugin v5.45.0

How are you running OpenRewrite?

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
   </properties>
   
   <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                   <source>${maven.compiler.source}</source>
                   <target>${maven.compiler.target}</target>
                </configuration>
   </plugin>

I see the following changes after the recpie got executed.

    <properties>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
   </properties>
   
   <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                   <release>21</release>
                </configuration>
   </plugin>

My expectation

    <properties>
   </properties>
   
   <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                   <release>21</release>
                </configuration>
   </plugin>

I apply UpgradeJavaVersion Recipie for Java 21 upgradation As part of the recpie's execution Firstly, source and target tags are replaced by release tag with 21 value Secondly, maven.compiler.source and maven.compiler.target property values are updated to 21 value

What did you expect to see?

If the property maven.compiler.source and maven.compiler.target are removed as part of first recpie execution, then why to update the removed properties and keep them in the code.

This leads to stale and unused properties.

I was expecting if the properties are not use, the properties also should be removed as part of recpie.

Are you interested in contributing a fix to OpenRewrite?

I am interested in contributing to this. Want to know if the expectation of mine is valid or not.

sushmitha-malae avatar Jan 30 '25 07:01 sushmitha-malae

Hi @sushmitha-malae 👋 , are you okay if I reorder your text that it better match with our template?

MBoegers avatar Jan 30 '25 09:01 MBoegers

The recipe making this change if org.openrewrite.maven.UpdateMavenProjectPropertyJavaVersion which greedily upgrades maven properties

  • java.version
  • jdk.version
  • javaVersion
  • jdkVersion
  • maven.compiler.source
  • maven.compiler.target
  • maven.compiler.release
  • release.version

Because the recipe cannot make sure that this property is never referred, we don't remove them to not break downstream builds. If there is a convention in your project/organization to never read the value of these properties, the recipe org.openrewrite.maven.RemoveUnusedProperties can remove them for you.

MBoegers avatar Jan 30 '25 09:01 MBoegers