Skip to content

Add mapstruct-processor to annotation processor paths when Lombok and MapStruct are used#1175

Merged
timtebeek merged 4 commits into
mainfrom
tim/1174-mapstruct-annotation-processor
Jul 24, 2026
Merged

Add mapstruct-processor to annotation processor paths when Lombok and MapStruct are used#1175
timtebeek merged 4 commits into
mainfrom
tim/1174-mapstruct-annotation-processor

Conversation

@timtebeek

@timtebeek timtebeek commented Jul 24, 2026

Copy link
Copy Markdown
Member

Problem

When a project uses both Lombok and MapStruct, UpgradeToJava17 (via AddLombokMapstructBinding + EnableLombokAnnotationProcessor) adds the lombok-mapstruct-binding and lombok annotation processor paths, but never adds mapstruct-processor. Without it on the annotation processor path, MapStruct generates no mapper code once annotation processing is configured explicitly (required from Java 23 onward).

Fix

New recipe org.openrewrite.java.migrate.AddMapstructAnnotationProcessorPath, wired into AddLombokMapstructBinding. It:

  • discovers the resolved org.mapstruct:mapstruct version, and
  • adds a mapstruct-processor <path> to the maven-compiler-plugin annotationProcessorPaths at that same version.

It reuses the upstream org.openrewrite.maven.AddAnnotationProcessor for the actual insertion (so multi-module placement, "already configured" detection, and maven-compiler-plugin 3.12+ managed-version handling all carry over), supplying the version discovered during the scan phase. No-op when MapStruct isn't present.

Tests

  • AddLombokMapstructBindingTest: new addMapstructProcessorForMaven; existing Maven cases updated to include the new path; doesNotDuplicateMaven extended to assert idempotency for the mapstruct-processor path too. Gradle cases are unaffected (the recipe is Maven-only).
  • UpgradeToJava17Test: new addsMapstructProcessorWhenLombokAndMapstructUsedWithoutAnnotationProcessorPaths exercising the full chain from the issue — mapstruct-processor is added and tracks the upgraded MapStruct 1.6.x version.

@timtebeek
timtebeek merged commit 7c45df7 into main Jul 24, 2026
1 check passed
@timtebeek
timtebeek deleted the tim/1174-mapstruct-annotation-processor branch July 24, 2026 21:36
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Java 17 - Lombok Annotation Processors - include mapstruct

1 participant