Skip to content

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

Description

@SanjayVas

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"],
)

Activity

  1. restingbull commented on Jan 5, 2024

    @restingbull
    Collaborator

    Where are the native libraries coming from in the example?

  2. SanjayVas commented on Jan 8, 2024

    @SanjayVas
    Author

    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.

  3. TwoClocks commented on Oct 1, 2024

    @TwoClocks

    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.

  4. SanjayVas commented on Oct 1, 2024

    @SanjayVas
    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.

  5. TwoClocks commented on Oct 1, 2024

    @TwoClocks

    @SanjayVas Works great. Thanks!

  6. github-actions commented on Mar 12, 2026

    @github-actions

    Thanks for your contributions to rules_kotlin!
    This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days.

  7. SanjayVas commented on Mar 13, 2026

    @SanjayVas
    Author

    Still needs fixing. We have many TODOs in our codebase waiting for this.

  8. SanjayVas commented on Sep 14, 2026

    @SanjayVas
    Author

    Looks like #1498 got reverted in #1740 so this issue should be reopened until the replacement #1742 is merged.

  9. Bencodes commented on Sep 15, 2026

    @Bencodes
    Collaborator

    Looks like #1498 got reverted in #1740 so this issue should be reopened until the replacement #1742 is merged.

    I accidentally merged this PR and and revered so that the present changes could get re-reviewed by someone.

    Are you able to test this out against your project and let us know if it works?

  10. SanjayVas commented on Sep 15, 2026

    @SanjayVas
    Author

    It's messy in our current set of modules to use unreleased versions of rules_kotlin.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions