franzbecker / gradle-lombok

Gradle plugin for Lombok support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using the plugin in Intellij does not find lombok classes

ieugen opened this issue · comments

Hi,

I've added the plugin to my project and it build ok with Gradle. However, Idea does not see the dependencies. That means the plugin might not add them to the classpath.

I've also tried to help Idea but it did not work for me:

idea {
    module {
        scopes.COMPILE.plus += [configurations.compileOnly, configurations.lombok]
    }
}

Having the plugin and the dependencies does not work for Intellij.
Having just the dependencies, works.
With the setup bellow I have tried:

  • lombok dependencies without gradle-lombok - it works
  • lombok dependencies and gradle-lombok - Idea marks lombok as not found, compilation works because it is delegated to Gradle in my setup
  • no lombok dependencie and gradle-lombok - missing dependencies, same as above

What do I expect:

  • if the plugin is applied I expect it to work the same as in the case of me adding the dependencies on the classpath.

What I suspect, is that 'idea' plugin does not see the changes that gradle-lombok performs. It might run before it applies ?

plugins {
    id 'java-library'
    id 'idea'
    id 'eclipse'
    id 'io.franzbecker.gradle-lombok' version '1.12'
}
dependencies {
    compileOnly "org.projectlombok:lombok:${lombokVersion}"
    testCompileOnly "org.projectlombok:lombok:${lombokVersion}"
...
}

This issue starts with new version 1.12, downgrade to 1.11 and all will work fine.

Bummer :( . Thanks for the info. I will try it out and get back with feedback if it does not work.

Could you please updated the docs or make a new release so people don't come back with the same issue or think the plugin is no good?

Sorry for the inconvenience. This seems to be an issue with IntelliJ and was introduced in the most recent PR #35.

@franzbecker Sorry for that. It looks like we should use "implementation" instead of "compileOnly".

https://docs.gradle.org/4.6/release-notes.html#convenient-declaration-of-annotation-processor-dependencies

Maybe I copied some wrong codes. So the code should be something like this.

        boolean atLeastGradle4_6 = GradleVersion.version(project.gradle.gradleVersion) >= GradleVersion.version('4.6')
        if (atLeastGradle4_6) {
            project.configurations.getByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME).extendsFrom(configuration)
            project.configurations.getByName(JavaPlugin.ANNOTATION_PROCESSOR_CONFIGURATION_NAME).extendsFrom(configuration)
            project.configurations.getByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME).extendsFrom(configuration)
            project.configurations.getByName(JavaPlugin.TEST_ANNOTATION_PROCESSOR_CONFIGURATION_NAME).extendsFrom(configuration)
        } else {
            project.configurations.getByName("compile" /* JavaPlugin.COMPILE_CONFIGURATION_NAME */).extendsFrom(configuration)
            project.configurations.getByName(JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME).extendsFrom(configuration)
        }

I think we can safely use string constant "compile" instead of already deprecated JavaPlugin.COMPILE_CONFIGURATION_NAME since it will not be changed anymore.

One thing I'm not sure is the needs of TEST_*_CONFIGURATION_NAME. Some examples contains this but I can not find official documents. In my tests, everything was fine without these.

I will open PR for this.

Trying to help: a good visualization of the configurations and the relationships is on the java-library page:

https://docs.gradle.org/current/userguide/java_library_plugin.html