What version of OpenRewrite are you using?
- OpenRewrite plugin v7.23.0
- rewrite-recipe-bom v3.4.0
- rewrite-migrate-java (from BOM)
How are you running OpenRewrite?
Gradle plugin via init script on a multi-module project (~200 modules).
initscript {
repositories {
maven { url "https://plugins.gradle.org/m2" }
}
dependencies { classpath("org.openrewrite:plugin:7.23.0") }
}
rootProject {
plugins.apply(org.openrewrite.gradle.RewritePlugin)
dependencies {
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.4.0"))
rewrite("org.openrewrite.recipe:rewrite-migrate-java")
}
rewrite {
activeRecipe("org.openrewrite.java.migrate.UpgradeToJava21")
}
}
What is the smallest, simplest way to reproduce the problem?
package com.example;
import lombok.*;
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Data
@EqualsAndHashCode
public class AuthHeaders {
String authHeader;
String token;
}
Run: ./gradlew --init-script init.gradle rewriteRun
Note: The bug occurs in multi-module projects. I could not reproduce it in a single-module project.
What did you expect to see?
Either unchanged code, or expanded explicit imports:
package com.example;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Data
@EqualsAndHashCode
public class AuthHeaders {
String authHeader;
String token;
}
What did you see instead?
The import lombok.*; line was removed without replacement:
package com.example;
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Data
@EqualsAndHashCode
public class AuthHeaders {
String authHeader;
String token;
}
This breaks compilation because the Lombok annotations are no longer imported.
Scale of impact
In our project, rewriteDryRun reports:
- 95 files lose
import lombok.*;
- 0 files gain explicit lombok imports
The recipe chain shows:
org.openrewrite.java.migrate.UpgradeToJava21
org.openrewrite.java.migrate.UpgradeToJava17
org.openrewrite.java.migrate.Java8toJava11
org.openrewrite.java.migrate.lombok.UpdateLombokToJava11
org.openrewrite.java.migrate.lombok.LombokValToFinalVar
What is the full stack trace of any errors you encountered?
No stack trace. The recipe completes successfully but produces invalid code.
Are you interested in contributing a fix to OpenRewrite?
Yes, with guidance on where the import removal logic resides.
What version of OpenRewrite are you using?
How are you running OpenRewrite?
Gradle plugin via init script on a multi-module project (~200 modules).
initscript { repositories { maven { url "https://plugins.gradle.org/m2" } } dependencies { classpath("org.openrewrite:plugin:7.23.0") } } rootProject { plugins.apply(org.openrewrite.gradle.RewritePlugin) dependencies { rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.4.0")) rewrite("org.openrewrite.recipe:rewrite-migrate-java") } rewrite { activeRecipe("org.openrewrite.java.migrate.UpgradeToJava21") } }What is the smallest, simplest way to reproduce the problem?
Run:
./gradlew --init-script init.gradle rewriteRunNote: The bug occurs in multi-module projects. I could not reproduce it in a single-module project.
What did you expect to see?
Either unchanged code, or expanded explicit imports:
What did you see instead?
The
import lombok.*;line was removed without replacement:This breaks compilation because the Lombok annotations are no longer imported.
Scale of impact
In our project,
rewriteDryRunreports:import lombok.*;The recipe chain shows:
What is the full stack trace of any errors you encountered?
No stack trace. The recipe completes successfully but produces invalid code.
Are you interested in contributing a fix to OpenRewrite?
Yes, with guidance on where the import removal logic resides.