Skip to content

MapStruct integration: mapper fails when MapStruct runs first and every marked bean is outside builderGenerationPackages #383

Open

Description

@AndreasIgel

Problem

If MappingProcessor runs before BuilderProcessor and no @SimpleBuilder bean is inside simplebuilder.builderGenerationPackages, compilation fails:

No implementation was created for PersonMapper due to having a problem in the erroneous element other.PersonDto.

This reproduces on main and after #379. With builder-first ordering it compiles, and the mapper falls back to setters.

Cause

  1. Round 1: MapStruct asks MapStructBuilderProvider for the bean's builder. The registry is not final yet, so it throws TypeHierarchyErroneousException and MapStruct defers the mapper.
  2. BuilderProcessor plans no task, finalizes the registry in endRound, and writes no source.
  3. No new sources means javac starts no further regular round, only the processing-over round. In 1.6.3, MapStruct's MappingProcessor does not retry deferred mappers there. It only reports the error.

If at least one in-scope builder is generated, a second round runs and the deferred mapper succeeds.

Proposed fix

MapStructBuilderProvider.isBuilderGenerationTarget checks only the marker annotations. Let it also apply the builderGenerationPackages scope (the provider already receives the processor options). A marked bean outside the scope can never get a builder, so the provider should return "no builder" right away instead of deferring.

Test

Add a MapStructSpiIntegrationTest case with mapStructCompiler(new MappingProcessor(), new BuilderProcessor()) and -Asimplebuilder.builderGenerationPackages=scoped. Check that the build succeeds, the mapper uses no builder, and it maps via setters.

Activity

  1. modified the milestones: v0.8.0, v0.7.0 on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions