MapStruct and Lombok not working together

前端 未结 5 899
陌清茗
陌清茗 2020-11-28 05:05

Tech Stack being used :

Java 8 MapStruct : 1.2.0.Final Lombok: 1.16.18 IDE: IntelliJ - Lombok Plugin already installed

  • Initially, I faced issues when
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 05:42

    The reason why it does not work is because Maven only uses the MapStruct processor and not the Lombok one. The annotationProcessorPaths tells maven which processors it should use.

    The delombok does nothing as you are ending up with 2 files per class and I think that the maven compiler does not see them.

    You have 2 options:

    Option 1: Add the lombok dependency in the annotationProcessorPaths

    
        org.apache.maven.plugins
        maven-compiler-plugin
        3.6.1
        
            ${java.version}
            ${java.version}
            
                
                    org.mapstruct
                    mapstruct-processor
                    ${org.mapstruct.version}
                
                
                    org.projectlombok
                    lombok
                    ${org.projectlombok.version}
                
                
                
                    org.projectlombok
                     lombok-mapstruct-binding
                    0.1.0
                
            
        
    
    

    Option 2:

    Add the mapstruct-processor dependency to your dependencies and remove the annotationProcessorPaths. This way the maven compiler will pick up all the annotation processors that are in your dependencies.

    I would advise in using Option 1, as with that you can be certain that you are not using some MapStruct transitive dependencies and internal classes in your code.

    Edit:

    To make sure that the IntelliJ annotation processing also works you will have to add the mapstruct-processor as a provided dependency due to IDEA-150621. IntelliJ in the moment does not use the annotationProcessorPaths from Maven to configure the project correctly.

    Edit 2:

    Add information about lombok-mapstruct-binding needed from Lombok 1.18.16.

提交回复
热议问题