Skip to content

Generated mappers for Spring can be package-private #2513

Description

@pdelaby

Working with Spring, Java > 1.8 and Mapstruct 1.4.2.Final.

The mappers generated for Spring ( componentModel = "spring") are implementing an interface, annotated with @Component, so they don't need to be public, they can be package-private by default.

They are meant to be injected by Spring in other classes/services, so the usual client code don't needs to do new MyMapperImpl();

Can you add a way to generate package-private implementations?

In a project, it can be detected by running test using ArchUnit ( this test with fail due to MapStruct generated classes).

ArchRuleDefinition.noClasses()
            .that()
            .haveSimpleNameEndingWith("Impl")
            .should().bePublic()
            .because("Implementations don't need to be public")
            .check(new ClassFileImporter().withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS).importPackages("my.nice.pacakge"));

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions