How to configure lombok and mapstruct with Gradle

Posted by itungnt on Friday, December 20, 2019

I created a new Kotlin project and want to import my old project.

Old configuration

My new Kotlin project was configured to use Mapstruct and the build.gradle look like

apply plugin: 'kotlin-kapt'

dependencies {
    implementation "org.mapstruct:mapstruct:${mapstructVersion}"
    kapt "org.mapstruct:mapstruct-processor:${mapstructVersion}"
}

When I want to use lombok for the java project. I added the dependencies but it doesn’t work.

implementation "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"

The ./gradlew build just give the error of no Getter/Setter found, that means lombok was not processing when build. Which works fine with IntelliJ IDEA because of the lombok plugins

New Configuration

After a lot of research with lombok and Gradle it turned out that my configuration was totally fine. The problem is the conflict between kapt and Gradle annotationProcessor

In the end I just remove kapt and use annotationProcessor for both

    // Mapstruct
    implementation "org.mapstruct:mapstruct:${mapstructVersion}"
    annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
  
    // Lombok
    implementation "org.projectlombok:lombok:${lombokVersion}"
    annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
    testImplementation "org.projectlombok:lombok:${lombokVersion}"
    testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"

comments powered by Disqus