anvil icon indicating copy to clipboard operation
anvil copied to clipboard

Compiler runs indefinitely for incremental build

Open apramana opened this issue 3 years ago • 4 comments

Steps to reproduce - perform these steps with build cache disabled for consistency:

  1. Build this project and it compiles successfully.
  2. Uncomment the method in Feature1Component and build - compilation does not complete.
  3. Clean build without cache and it compiles successfully again.

apramana avatar Oct 26 '22 02:10 apramana

I'm sorry for the long delay. Is this still an issue? If yes, can you please share a build scan. JVM version + OS could make a difference.

vRallev avatar Jan 10 '23 21:01 vRallev

It's still reproducible for me. I also tried updating the project's dependencies: Kotlin = 1.8.0 AGP = 7.4.0 Dagger = 2.44.2 Anvil = 2.4.4

Be sure to perform the steps with build cache disabled for consistency.

I'm not sure how to capture a build scan from a build that never completes, but here's one from a successful run of that project.

Also, I noticed that directories in build/anvil/... are getting created and deleted repeatedly.

apramana avatar Jan 14 '23 02:01 apramana

I can reproduce the issue and it's super weird. Compilation in the library module is successful, stub generation in the app module is successful, but the Kotlin compile task in the app module hangs. I upgraded Kotlin and Anvil as well. Same failure. I also see the issue with the files being recreated over and over again.

The issue does not reproduce, if I run Kotlin compilation in-process to debug the issue. It only happens with the Kotlin daemon.

I've modified Anvil to add log messages to debug the problem this way and now it gets interesting. The Kotlin compiler keeps registering a new instance of the Anvil compiler plugin, runs all code generation and then repeats this in an endless loop. Our code generation logic is what clears the Anvil folders. This seems to be a bug in the Kotlin compiler. The stacktrace for registering the Anvil compiler plugin is

ava.lang.IllegalStateException
	at com.squareup.anvil.compiler.AnvilComponentRegistrar.registerProjectComponents(AnvilComponentRegistrar.kt:64)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerExtensionsFromPlugins$cli(KotlinCoreEnvironment.kt:656)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$ProjectEnvironment.registerExtensionsFromPlugins(KotlinCoreEnvironment.kt:169)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.configureProjectEnvironment(KotlinCoreEnvironment.kt:566)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:199)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:108)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:445)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createCoreEnvironment(K2JVMCompiler.kt:192)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:143)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:53)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:99)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:47)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:475)
	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:125)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:373)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally$default(IncrementalCompilerRunner.kt:318)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:180)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:79)
	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:625)
	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:101)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1746)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

I'll file a ticket for JetBrains.

vRallev avatar Jan 14 '23 06:01 vRallev

https://youtrack.jetbrains.com/issue/KT-55940

vRallev avatar Jan 14 '23 06:01 vRallev