Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 8 compiler cannot compile Lombok annotations when used with Gradle 4.6 or Gradle 4.7 and java compiler fork option is true #1671

Closed
timtelcik opened this issue Apr 21, 2018 · 10 comments

Comments

@timtelcik
Copy link

timtelcik commented Apr 21, 2018

Issue

Java 8 compiler cannot compile Lombok annotations when used with Gradle 4.6 or Gradle 4.7 and java compiler fork option is true.

This issue appears related to Gradle issue 1603:

This issue does not occur when using Gradle 4.5.1.

Environments

Valid Environments

Gradle 4.5.1 + Lombok 1.16.6/1.16.20) + JDK 1.8.0_171 + MS Windows 7
Gradle 4.5.1 + Lombok 1.16.6/1.16.20) + JDK 1.8.0_171 + Apple Mac OS 10.12.6

Invalid Environments

  • Gradle 4.6/4.7 + Lombok 1.16.6/.16.20) + JDK 1.8.0_171 + MS Windows 7
  • Gradle 4.6/4.7 + Lombok 1.16.6/1.16.20 + JDK 1.8.0_171 + Apple Mac OS 10.12.6

Gradle Java Compiler Log

$ gradle build --stacktrace

> Task :Code:Common:AdrDomainModels:compileJava
.../src/main/java/XXX/Address.java:63: warning: Can't initialize javac processor due to (most likely) a class loader problem: java.lang.NoClassDefFoundError: com/sun/tools/javac/processing/JavacProcessingEnvironment
public class Address implements Identifiable, Serializable {
       ^
        at lombok.javac.apt.Processor.init(Processor.java:84)
        at lombok.core.AnnotationProcessor$JavacDescriptor.want(AnnotationProcessor.java:87)
        at lombok.core.AnnotationProcessor.init(AnnotationProcessor.java:141)
        at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.init(AnnotationProcessor.java:53)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.<init>(JavacProcessingEnvironment.java:500)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.next(JavacProcessingEnvironment.java:597)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:690)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
        at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
        at org.gradle.api.internal.tasks.compile.IncrementalAnnotationProcessingCompileTask.call(IncrementalAnnotationProcessingCompileTask.java:76)
        at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:50)
        at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:36)
        at org.gradle.api.internal.tasks.compile.daemon.AbstractDaemonCompiler$CompilerCallable.call(AbstractDaemonCompiler.java:88)
        at org.gradle.api.internal.tasks.compile.daemon.AbstractDaemonCompiler$CompilerCallable.call(AbstractDaemonCompiler.java:76)
        at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:42)
        at org.gradle.workers.internal.WorkerDaemonServer.execute(WorkerDaemonServer.java:46)
        at org.gradle.workers.internal.WorkerDaemonServer.execute(WorkerDaemonServer.java:30)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:101)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
        at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:155)
        at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:137)
        at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
        at java.lang.Thread.run(Thread.java:748)
  Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.processing.JavacProcessingEnvironment
        at java.lang.ClassLoader.findClass(ClassLoader.java:530)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at lombok.launch.ShadowClassLoader.loadClass(ShadowClassLoader.java:418)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 43 more
XXX/Address.java:184: error: cannot find symbol
                return getAddressIdentificationNumber();
                       ^
  symbol:   method getAddressIdentificationNumber()
  location: class Address
XXX/Address.java:189: error: cannot find symbol
                getLandAddresses().add(landAddress);
                ^
  symbol:   method getLandAddresses()
  
...

53 errors
1 warning

> Task :Code:Common:AdrDomainModels:compileJava FAILED

FAILURE: Build failed with an exception.  

Workaround

  • Disable gradle java compilation forking.

e.g.

        compileJava {
            options.fork = false
            options.incremental = false
        }
@timtelcik timtelcik changed the title Lombok can't invoke Java 8 compiler if isFork=true in Gradle 4.7 Lombok 1.16.x can't invoke Java 8 compiler if isFork=true in Gradle 4.7 Apr 21, 2018
@timtelcik timtelcik changed the title Lombok 1.16.x can't invoke Java 8 compiler if isFork=true in Gradle 4.7 Lombok 1.16.x can't invoke Java 8 compiler fork option is true in Gradle 4.7 Apr 21, 2018
@timtelcik timtelcik changed the title Lombok 1.16.x can't invoke Java 8 compiler fork option is true in Gradle 4.7 Java 8 compiler cannot compile Lombok annotations when used with Gradle 4.7 and java compiler fork option is true Apr 21, 2018
@victorwss
Copy link
Contributor

You need to use Java9+ to compile lombok!

@timtelcik
Copy link
Author

timtelcik commented Apr 28, 2018

Hello @victorwss,

I can use Gradle 4.7 + Lombok 1.16.6 (or 1.16.20) + JDK 1.8.x + MS Windows 7,
but cannot use Gradle 4.7 + Lombok 1.16.6 (or 1.16.20) + JDK 1.8..x + Apple Mac OS 10.12.6
with Gradle compiler options.fork=true.

So, for JDK 1.8 + MS Windows 7, the lombok compilation is OK, but for Mac OS the lombok compilation fails.

Are you advising Java 9.x is required for Mac OS?

Regards,

Tim

@Maaartinus
Copy link
Contributor

@timtelcik To get a user notified, you need to mention them like this: @victorwss

@victorwss
Copy link
Contributor

See #1659.

@Maaartinus
Copy link
Contributor

@timtelcik @victorwss Now really reading this issue, I'm unsure if you're both speaking about the same thing. The OP says "Java 8 compiler cannot compile Lombok annotations", but seems to mean that Lombok doesn't work in his case rather then compiling Lombok from source. Then it's a known problem and AFAIK the described workaround is all what can done at the moment.

@timtelcik
Copy link
Author

Thanks for the update, @Maaartinus.

The exception states that class "com.sun.tools.javac.processing.JavacProcessingEnvironment" cannot be located, however the stack trace includes class "com.sun.tools.javac.processing.JavacProcessingEnvironment".

My interpretation (based on that information only) is the compiler loses state/context when the compiler thread is forked.

Something weird going on with forking when using JDK 1.8.x (8.x) with Mac OS X 10.12+.

For now, I have a workaround.

Thanks,
Tim

@timtelcik
Copy link
Author

timtelcik commented Apr 30, 2018

Hello @Maaartinus and @victorwss,

Further investigation indicates this issue is related to using Gradle 4.6 or Gradle 4.7. This issue does not appear to be a Lombok issue.

I am now seeing the same compiler forking issue for MS Windows 7 and Mac OS 10.12 with JDK 1.8.x.

This issue does not occur when using Gradle 4.5.1.

Hence, Lombok issue #1671 is effectively the same as Gradle issue #1603

I think we can close Lombok issue #1671 .

Regards,

Tim

@timtelcik timtelcik changed the title Java 8 compiler cannot compile Lombok annotations when used with Gradle 4.7 and java compiler fork option is true Java 8 compiler cannot compile Lombok annotations when used with Gradle 4.6 or Gradle 4.7 and java compiler fork option is true Apr 30, 2018
@rzwitserloot
Copy link
Collaborator

@victorwss is misunderstanding the problem; disregard that advice.

You need javac9 to compile lombok itself, but that's only for us lombok hackers.

To use lombok, all you need is, anything really. (Well, a java6+, but, hey, it's 2018).

Given that the stack trace clearly indicates a javac is in the chain, but the loader can't find a javac related class, it sounds like gradle is doing something non-standard to javac. I can't complain; lombok also does non-standard things to javac, but at least we can hide behind the fact that it's impossible to do what we do without doing non-standard things to javac :)

I'm going to shut this one down, we're planning on doing a bunch of gradle integrations anyway, and this will probably (?) disappear by itself. There's a workaround and this sounds tricky to reproduce.

@timtelcik
Copy link
Author

Thanks for the update, @rzwitserloot,

maybe we can progress to a solution via Lombok issue 1603 at

Lombok can't invoke compiler if isFork=true in Gradle 4.6

#1603

Regards,

Tim

@BigSully
Copy link

Gradle 4.5.1 solve the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants