Skip to content

UpgradeJavaVersion recipe does not work properly when a Java version isn't explicitly specified #514

@cjobinabo

Description

@cjobinabo

What version of OpenRewrite are you using?

I am using

  • rewrite-migrate-java 1.4.2
  • Maven plugin 5.32.1

How are you running OpenRewrite?

CLI

Problem statement

The UpgradeJavaVersion recipe currently does nothing when no Java version is specified in a project's pom.xml file. So, in the case where a user runs the org.openrewrite.java.migrate.UpgradeBuildToJava21 recipe without setting a compiler version in their pom.xml, the app would still compile at Maven's default compile version, which I believe is 1.8.

How To Reproduce

Remove the maven.compiler.target, and maven.compiler.source properties in the pom.xml file and execute dryRun with any UpgradeJavaVersion recipe specified as an active recipe. You will see that the UpgradeJavaVersion made no changes, indicating the app is still building at the default maven compiler version.

Expected behavior

I think these recipes should instead set the source and target compile version when no values were previously specified

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions