1

I was about building a gradle 5 project in IDEA. The lombok dependency was set to compileOnly in the build.gradle file and running it resulted in success from command line and IDEA gradle tool as well.

"Funny" fact, that lombok isn't included in Source Sets, so my lombok imports are failing....

I googled for it, and in theory since IDEA 2017.2 + Gradle 4 it's a fixed issue, IDEA should pick up compileOnly dependencies as well.

In the reality, it does not work. Any Gradle plugin, or idea to solve this issue? :)

Thanks.

ui.:

VERSION 1 Using compileOnly & annotationProcessor both for prod code and tests resulted in

  • from command-line, gradle is able to run everything with SUCCESS
  • from IDEA, it's impossible, imports are failing with lombok

VERSION 2 Using compile & annotationProcessor

  • from command-line, gradle is able to run everything with SUCCESS
  • from IDEA, imports are OK, everything is fine

dependencies {...compileOnly "org.projectlombok:lombok:${lombokVersion}" annotationProcessor("org.projectlombok:lombok:${lombokVersion}") testCompileOnly "org.projectlombok:lombok:${lombokVersion}" testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}")...}

Source Sets IntelliJ IDEA 2018.3

Idea Import's failed

lombocska
  • 210
  • 3
  • 11
  • when executing `./gradlew dependencies` in command line, do you see `lombok` dependency in the `compileClasspath` and/or `compileOnly`configurations? as said in answer below this should work in IDEA, nothing else to configure (just tested with IDEA 2018.3.4 / lombok 1.18.6 / Gradle 5.2.1 : no issue). Also remember to add `lombok` dependency to `testCompileOnly` and `testAnnotationProcessor` if you use lombok annotations in test classes. – M.Ricciuti Feb 20 '19 at 12:43
  • Can you build by Gradle from command line? – Andrey Feb 20 '19 at 16:57
  • I extended my description, because my main problem is not with the command line. :) In case of ./gradlew dependencies command, everithing is fine, resulted in SUCCESS, lombok is there in both of the **testCompileClasspath**, **testCompileOnly**. But not in source sets picked up by IDEA, and if i am trying to run tests from IDE, it is failing with import issues. – lombocska Feb 21 '19 at 10:33
  • Possible duplicate of [Lombok annotations do not compile under Intellij idea](https://stackoverflow.com/questions/24006937/lombok-annotations-do-not-compile-under-intellij-idea) – Makoto Feb 22 '19 at 06:41
  • Have you read my description properly? @makoto It's not that case, since the problem is not my IDEA settings (enable annotation processors). The problem is how IDEA handles `compile` and `compileOnly` gradle keywords. What you linked is from 2014 with an old IDEA and gradle version. – lombocska Feb 25 '19 at 09:23
  • I've hit the same issue so it's not just you. Works perfectly on the command line but IntelliJ fails to bring Lombok as a 'compileOnly' dependency. I've gone for your Version 2 as a workaround. – Jason Royals Mar 10 '19 at 00:30
  • I posted a fix at https://stackoverflow.com/questions/55227728/cannot-find-symbol-error-lombok-1-18-6-does-not-work-with-gradle-5-2-1-jdk-10 – ap6491 Mar 18 '19 at 18:35
  • Thanks @ap6491 :) After struggling with this issue, I had decided to transform my whole project using maven, since gradle wasn't so clean for me as maven. :/ – lombocska Mar 20 '19 at 12:25
  • 2
    I was struggling with this problem yesterday and stumbled on this issue here. I updated to v2019.1 today and it shows everything properly now. https://i.stack.imgur.com/liwx6.png – sbsatter Apr 11 '19 at 04:44

2 Answers2

0

According to https://projectlombok.org/setup/gradle you need to write in your build.gradle

dependencies {
    compileOnly 'org.projectlombok:lombok:1.18.6'
    annotationProcessor 'org.projectlombok:lombok:1.18.6'
}

It works for me

shaloms
  • 21
  • 4
  • 1
    Yes, My build.gradle file looks like this, both of them added as you wrote, but IDE hasn't picked up lombok, if I am using `compileOnly` instead `compile`. – lombocska Feb 20 '19 at 12:08
0

You can upgrade the IDEA version to 2019.1 or use the 4.x version of Gradle.

double-beep
  • 5,031
  • 17
  • 33
  • 41
qatang
  • 63
  • 1
  • 4