gradleintellij-idealombokjunit5intellij-lombok-plugin

NoSuchMethodError - Intellij and lombok


I am getting a weird issue in IntelliJ. I am using Lombok (1.18.2), IntelliJ(2018.2.2) and JUnit 5 in gradle 4 multi-module project.

It took me hours to replicate this.

  1. Run all test case with coverage.

  2. Following a pop up will come

enter image description here

  1. if I press OK and re-run the unit test case. It will start failing with java.lang.NoSuchMethodError for the getters and setters.

  2. removing Lombok and generating getter and setter after this has no effect as well.

Tried everything to fix this (enable annotation processor, Lombok plugin, clean build) but no luck.

EDIT 1:

Root build.gradle:

implementation 'org.projectlombok:lombok:1.18.2'
testImplementation('org.junit.jupiter:junit-jupiter-api:5.3.1')
testImplementation('org.junit.jupiter:junit-jupiter-params:5.3.1')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.3.1')
testImplementation("org.junit.platform:junit-platform-launcher:1.3.1")
testImplementation("org.junit.vintage:junit-vintage-engine:5.3.1")
testImplementation "org.mockito:mockito-core:2.+"
testImplementation('org.mockito:mockito-junit-jupiter:2.22.0')

sub-project build.gradle

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

Solution

  • I solved this issue by making following changes:

    1. Enable annotation processing in Intellij.(File | Settings | Build, Execution, Deployment | Compiler | Annotation Processors)

    2. select processor path and point to lombok-1.18.4.jar because I just want to enable it for Lombok and not for Mapstruct. If enabled for both then it generates the Mapstruct classes in default location.

    3. under File "Invalidate cache and restart"

    4. under Build option "Rebuild project"

    This will solve it. It took me a while to make it working in Intellij.