bazelbuild / rules_kotlin

Bazel rules for Kotlin
Apache License 2.0
334 stars 211 forks source link

kt_jvm_test does not include native library paths in java.library.path #1088

Open SanjayVas opened 11 months ago

SanjayVas commented 11 months ago

java_test collects the paths to native libraries from JavaInfo.transitive_native_libraries and specifies them in the java.library.path property. kt_jvm_test does not do this.

The current workaround if loading native libraries is to use a combination of java_test and kt_jvm_library instead. e.g.

kt_jvm_library(
    name = "my_test",
    srcs = ["MyTest.kt"],
)

java_test(
    name = "MyTest",
    test_class = "package.for.MyTest",
    runtime_deps = [":my_test"],
)
restingbull commented 10 months ago

Where are the native libraries coming from in the example?

SanjayVas commented 10 months ago

Sorry, I guess I forgot to include that part in the workaround example. The native dep would be a shared library (cc_binary target with linkshared = True) specified in the deps of the library target.

TwoClocks commented 1 month ago

This is also true for kt_jvm_binary. You can not add cc_library dep via tuntime_deps. Both kt_jvm_binary and kt_jvm_test fail with this error.

Error in check_provider_instances: at index 0 of runtime_deps, got element of type NoneType, want JavaInfo

For kt_jvm_binary you can work around this by using java_binary, and adding Kt to the end of the class name.

But there isn't a work around for kt_jvm_test. AFAICT there is no way to write a test that requires a .so from the project.

SanjayVas commented 1 month ago

@TwoClocks The workaround I mentioned above (using java_test) does work for running tests written in Kotlin transitively depending on a native library. In my project, we've made a reference to this issue every time we've used that workaround.

TwoClocks commented 1 month ago

@SanjayVas Works great. Thanks!