Lombok-intellij-plugin: Lombok integration stops working if lombok is included as gradle's compileOnly

Created on 1 Apr 2016  路  13Comments  路  Source: mplushnikov/lombok-intellij-plugin

If I use a (new in Gradle 2.12) compileOnly dependency to include Lombok in my project, the Gradle build succeeds but the IntelliJ one does not, failing on all Lombok generated code.

dependencies {
  compile group: 'org.projectlombok', name: 'lombok', version: '1.16.8'
}

works, but

dependencies {
  compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.16.8'
  testCompileOnly group: 'org.projectlombok', name: 'lombok', version: '1.16.8'
}

does not

invalid

Most helpful comment

I am seeing this too on Ubuntu 16.04:

IntelliJ IDEA 2016.2.4
Build #IC-162.2032.8, built on September 9, 2016
JRE: 1.8.0_112-release-b343 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

All 13 comments

Could you please provide the version of a IntelliJ you are running as well as version of the lombok plugin?

I've just tested on 14.1.6, 15.0.4, 2016.1, as well as latest trunk of IntelliJ and it seems to be working as expected. I have also removed .idea folder and re-imported sample project in every version mentioned above, but could not reproduce your issue.

Can you please also check under module settings -> Dependencies, if lombok is added and marked as "provided".

IDEA 15.0.5, lombok plugin 0.11.15.
Simple test project build.gradle:

apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
repositories {
    mavenCentral()
}
test { useTestNG() }

dependencies {
    compile "org.slf4j:slf4j-api:1.7.21"
    compile "ch.qos.logback:logback-classic:1.1.7"
    testCompile "org.testng:testng:6.9.10"
    compileOnly "org.projectlombok:lombok:1.16.8"
}

Sample class:

import lombok.Data;

@Data
public class Sample {
    private String code;
}

Sample test:

import lombok.extern.slf4j.Slf4j;
import org.testng.annotations.Test;
@Slf4j
public class SampleTest {
    @Test
    public void testSample() {
        Sample sample = new Sample();
        sample.setCode("test");
        log.info(sample.toString());
    }
}

Now lombok dependency marked as provided and I can run test from IDE, but gradle task test fails with error: package lombok.extern.slf4j does not exist...
Well, let's try to fix: add testCompileOnly "org.projectlombok:lombok:1.16.8" into dependencies.
Now lombok dependency marked as test, @Data became red, gradle tasks OK, but test run from IDE context menu fails.

Thanks for adding that, I hadn't gotten around to it yet.

Actually I still cannot reproduce this in latest stable version of IDEA.

if you have both testCompileOnly and compileOnly (which you must as per Gradle docs, Java Plugin 45.5 Dependency Management and you have refreshed your Gradle dependencies, IDEA correctly puts lombok in both main and test sourceSets as dependency. Gradle itself, from both command-line and via Gradle runner in IDEA will detect this.

As per docs, compileOnly extends compile, testCompile extends compile (not compileOnly) while testCompileOnly extends testCompile. This means that test sources will not see compileOnly.

This of course requires, as always to have annotation processing to be enabled for both main and test sources.

One very important thing to note, IDEA 2016.1 introduced proper support for Gradle sourceSets and I believe this is dependent on IDEA support for Gradle sourceSets.

This means IDEA 15 and below does not understand Gradle compileOnly properly and this is not related to the lombok plugin. This is pure Gradle dependency management feature of IDEA (and this will be an issue for any dependency).

I can confirm upgrading to 2016.1 fixed the problem for me.

same as @jorn86, caution: it seems that generate module for per source sets is required to fix the issue.

Im facing the same issue now. Im running in my mac.
This issue started occurring after i updated from 2016.1 to 2016.2

IntelliJ IDEA 2016.2.4
Build #IC-162.2032.8, built on September 9, 2016
JRE: 1.8.0_112-release-b343 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

I am seeing this too on Ubuntu 16.04:

IntelliJ IDEA 2016.2.4
Build #IC-162.2032.8, built on September 9, 2016
JRE: 1.8.0_112-release-b343 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

I'm seeing this since I updated to 2017.2 today:
compileOnly "org.projectlombok:lombok"
lleads to

Warning:Warning:root project 'hubbing-ingress-gateway': Unable to resolve additional project configuration.
Details: org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':hubbing-ingress-gateway-harness:compileOnly'.
Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find org.projectlombok:lombok:.
Required by:
project :hubbing-ingress-gateway-harness

I have to change this to
compile "org.projectlombok:lombok"

This is only for IntelliJ; gradle 3.4 from the cmdline has no problem.

One reason could be that the module has no code, only one jbehave story. Maybe that confuses the plugin?

Have you tried enabling generate module for per source sets ?

If you mean "Create separate module per source set" - that's enabled.

I had faced the issue which looks like this one because I forgot to enable annotation processing in IntelliJ IDEA. It is described for example here in SO - Lombok annotations do not compile under Intellij idea. So I'm putting this note in a hope it might help other people who are absent-minded like me and find this while googling for the issue.

When I build the project in IntelliJ IDEA 2017.3 public preview without annotation processing enabled it looks like getters are setters are not created by @Data annotation.

I kept Lombok dependency as compileOnly, enabled annotations and it compiled like I expected with getters and setters.

May be the reason for the error is different for each user. With me, the error was causing due to older version of the gradle plugin.

Older version: gradle-4.5.1
Newer version: gradle-4.9

Could not find method annotationProcessor() for arguments [org.projectlombok:lombok:1.16.20] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pedegie picture pedegie  路  4Comments

pavelgordon picture pavelgordon  路  4Comments

leialexisjiang picture leialexisjiang  路  5Comments

chrvip picture chrvip  路  5Comments

timothymdavis picture timothymdavis  路  4Comments