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

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

Open
SanjayVas opened this issue Dec 9, 2023 · 5 comments
Open

Comments

@SanjayVas
Copy link

SanjayVas commented Dec 9, 2023

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
Copy link
Collaborator

Where are the native libraries coming from in the example?

@SanjayVas
Copy link
Author

SanjayVas commented Jan 8, 2024

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
Copy link

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
Copy link
Author

@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
Copy link

@SanjayVas Works great. Thanks!

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

No branches or pull requests

3 participants