rules_kotlin icon indicating copy to clipboard operation
rules_kotlin copied to clipboard

Fail to compile Java stubs in mixed-kotlin/Java setting

Open pettermahlen opened this issue 2 years ago • 0 comments

This feels like a pretty obscure corner case, but in the following situation:

  1. A Bazel package with mixed Java and Kotlin sources, where the Java code references the Kotlin code, and
  2. A java-based (not sure if that's a necessary condition) plugin that doesn't generate any source code (not sure if that's a necessary condition).

Then the Compiling Java headers (building the -java-hjar.jar file) fails to compile the Java code with an error like error: could not resolve <AnyClassDefinedInKotlin>.

I think the issue is in how the dependencies for the Java stubs compilation is set up here and here. In the second case, the .abi.jar, which contains class file definitions from Kotlin, is added, and the build works. In my case, I seem to be hitting the first situation, and the build doesn't work because the ABI jar is missing from the classpath (instead, there is a kapt-generated-stub.jar file at the corresponding place in the classpath). I don't understand that code well enough to actually propose a solution.

The reason I ran into this is that I'm doing a blanket add of a Dagger SPI plugin across a wide range of builds when a given flag is enabled. SPI plugins get loaded by Dagger only when Dagger runs so I thought it it should be a no-op for packages where Dagger isn't used. But that's not the case, it actually breaks building as described above.

pettermahlen avatar Oct 23 '23 07:10 pettermahlen