projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.83k stars 2.37k forks source link

[BUG] Upgrading to android tools gradle plugin 3.6.0+ breaks lombok #2412

Open darekxan opened 4 years ago

darekxan commented 4 years ago

Describe the bug it appears there are no property assessors generated.

To Reproduce I've prepared minimal failing build: https://github.com/darekxan/lomboktest/tree/broken_3.6.1 (sources, build output there)

Expected behavior This one works, version 3.5.3 https://github.com/darekxan/lomboktest/tree/master (sources, build output there)

Version info:

CharlyLafon37 commented 4 years ago

It's really annoying. We can't update android gradle plugin in any of our projects because of this. @rzwitserloot @rspilker can you look at this bug please ?

rspilker commented 4 years ago

I don't know which is better, 3.5.3 or 3.6.1. I know that 3.5.3 doesn't fail the build. But there is a warning in the log that lombok is disabled. So probably the code doesn't do what you expect.

In your example, you've annotated TestModel with @Data, but you never call getTest().

rspilker commented 4 years ago

I've located the code: https://github.com/JetBrains/kotlin/blob/master/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/incrementalProcessors.kt

rspilker commented 4 years ago

My knowledge of Kotlin is limited, but is I look at the IncrementalProcessinEnvironment and the lombok source code at https://github.com/rzwitserloot/lombok/blob/master/src/core/lombok/core/AnnotationProcessor.java#L86 a possible solution is to not only see if there is a field delegate but also look for processingEnv.

This is only going to work if there is somewhere a com.sun.tools.javac.processing.JavacProcessingEnvironment.

Otherwise we need way more code to make it work with the Kotlin compiler.

rspilker commented 4 years ago

Can you see if the edge release fixes this problem?

AngryGami commented 4 years ago

Nope, it didn't help. I didn't manage to get plugin (net.ltgt.apt) to work, though I'm not sure it is strictly required. Without this plugin it still complaints about field access inside builder class e.g. like this:

@Builder
public class MyConfiguration {
    @Builder.Default
    public final Integer mWidth = 352;

    public static class MyConfigurationBuilder {
        private MyConfiguration buildWithOptions() {
            System.out.println("just as an example: " + this.mWidth);
            return null;
        }
    }
}

causing compilation error during build:

error: cannot find symbol
System.out.println("just as an example: " + this.mWidth);

I've first encounter this error in version of lombok 1.18.12 + android gradle plugin 3.6.2 + gradle 6.1.1. I've tried edge release and got same failure. Version of lombok that works is 1.16.20, even 1.16.22 already doesnt, so change that happened in between these two is causing trouble. Version of android gradle plugin doesn't seem to have any impact on the issue, I've tried with versions 3.5.2, 3.6.2 and 4.0.0 - all works with lombok 1.16.20 and none with 1.16.22+.

Rawi01 commented 4 years ago

@rspilker I managed to remove the warning by adding processingEnv and filer as field in https://github.com/rzwitserloot/lombok/blob/326955cde1e788c0038ab77d2db340666b5f568b/src/core/lombok/javac/apt/LombokProcessor.java#L469-L471 Unfortunately it still fails to compile the example project. A possible reason might be the IncrementalFiler defined in IncrementalProcessor. It seems like it collects a list of classes and skipping this might be a problem.

Rawi01 commented 4 years ago

You can compile your example if you add

project.afterEvaluate {
    def variants = project.android.applicationVariants + project.android.testVariants
    variants.each { var ->
        def task = tasks["compile${var.name.capitalize()}JavaWithJavac"]
        task.doFirst {
            task.options.compilerArgs=[]
        }
    }
}

to your build.gradle. There might be some side effects, I only tried your example project.

CharlyLafon37 commented 3 years ago

Does anyone have a solution for this ? The latest release 1.18.16 does not solve this issue.