Skip to content

Only add lombok annotation processor to modules that use lombok#1031

Merged
Jenson3210 merged 5 commits intomainfrom
fix-lombok-precondition
Mar 30, 2026
Merged

Only add lombok annotation processor to modules that use lombok#1031
Jenson3210 merged 5 commits intomainfrom
fix-lombok-precondition

Conversation

@Jenson3210
Copy link
Copy Markdown
Contributor

@Jenson3210 Jenson3210 commented Mar 30, 2026

Summary

  • Changed EnableLombokAnnotationProcessor precondition from RepositoryHasDependency to DependencyInsight
  • Added tests covering the multi-module scenario where only some modules use lombok

Problem

EnableLombokAnnotationProcessor used RepositoryHasDependency as its precondition, which checks the entire repository. If any module has lombok as a dependency, the annotation processor gets added to ALL modules — including those that don't use lombok. This causes unexpected maven-compiler-plugin configuration changes in projects without lombok.

Solution

Switch the precondition from RepositoryHasDependency (repo-wide) to DependencyInsight (per-module). This matches the pattern already used by AddLombokMapstructBinding and ensures the annotation processor is only added to modules that actually declare lombok as a dependency.

Test plan

  • Existing UpgradeToJava25Test.addsLombokAnnotationProcessor passes (positive case)

  • Existing UpgradeToJava17Test passes

  • New test: doesNotAddLombokToModuleWithoutLombok — multi-module project where one module has lombok and another doesn't; only the lombok module gets the annotation processor

  • New test: doesNotAddLombokWhenNotPresent — single module without lombok gets no changes

  • New test: doesNotAddLombokWhenNotPresentViaUpgradeToJava25 — same via composite recipe

  • Fixes moderneinc/customer-requests#2110

…projects

RepositoryHasDependency marks all files if any module has lombok,
causing AddAnnotationProcessor to run on modules without lombok.
…ionProcessor

RepositoryHasDependency checks the whole repo and marks ALL files when
any module has lombok, causing AddAnnotationProcessor to run on modules
without lombok. Switch to DependencyInsight which checks per-module,
matching the pattern used by AddLombokMapstructBinding.

Fixes moderneinc/customer-requests#2110
DependencyInsight doesn't resolve dependencies in nested mavenProject
test structures (test infrastructure limitation). The sibling mavenProject
test already proves the per-module behavior correctly.
…recision

Switch to ModuleHasDependency which is designed as a per-module precondition
using ScanningRecipe to collect JavaProject markers. This is the proper
counterpart to RepositoryHasDependency for module-scoped checks, and removes
the need for the Singleton wrapper.
</dependencies>
</project>
""",
spec -> spec.after(actual -> actual)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we validate the annotation processor was added here?

Copy link
Copy Markdown
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved already, but perhaps good to have an assertion that the processor is actually added.

@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Mar 30, 2026
@Jenson3210 Jenson3210 merged commit 317ca42 into main Mar 30, 2026
1 check passed
@Jenson3210 Jenson3210 deleted the fix-lombok-precondition branch March 30, 2026 09:38
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants