bazelbuild / rules_kotlin

Bazel rules for Kotlin
Apache License 2.0
331 stars 206 forks source link

Issue resolving java.lang.Record in java_library dependency from a kt_jvm_library #1149

Closed MorganRoff-UnlikelyAI closed 6 months ago

MorganRoff-UnlikelyAI commented 6 months ago

Hello, I have a kt_jvm_library rule that depends on a java_library rule. In the sources for that java_library I define a Java record type. I can build the java_library successfully, but when I try to build the kt_jvm_library, I get an error like this:

KotlinCompile //path:my_kt_lib { kt: 5, java: 0, srcjars: 0 } for k8 failed: (Exit 1): build failed: error executing KotlinCompile command (from target //path:my_kt_lib) ...
error: supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
    class my.java.RecordClass, unresolved supertypes: java.lang.Record
Adding -Xextended-compiler-checks argument might provide additional information.

I found this similar issue about strict transitive dependencies, but that seems resolved. I'm wondering if perhaps this is related to my toolchain setup?

My toolchain looks like this:

load("@io_bazel_rules_kotlin//kotlin:core.bzl", "define_kt_toolchain")

KOTLIN_LANGUAGE_LEVEL = "1.9"

JAVA_LANGUAGE_LEVEL = "17"

define_kt_toolchain(
    name = "kotlin_toolchain",
    api_version = KOTLIN_LANGUAGE_LEVEL,  # "1.1", "1.2", "1.3", "1.4", "1.5" "1.6", "1.7", "1.8", or "1.9"
    jvm_target = JAVA_LANGUAGE_LEVEL,  # "1.6", "1.8", "9", "10", "11", "12", "13", "15", "16", "17", "18", "19", "20" or "21"
    language_version = KOTLIN_LANGUAGE_LEVEL,  # "1.1", "1.2", "1.3", "1.4", "1.5" "1.6", "1.7", "1.8", or "1.9"
)
MorganRoff-UnlikelyAI commented 6 months ago

Also I'm using version 1.9.0 of rules_kotlin.

MorganRoff-UnlikelyAI commented 6 months ago

I resolved this by adding the following flags in .bazelrc: --tool_java_language_version=17 --tool_java_runtime_version=local_jdk_17

I previously had only the non tool_ version of these flags set to use Java 17, which was sufficient to build Java-only libraries, but I seem to need the tool_ prefix flags too when building Kotlin libraries.