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

Dependency .jar not found for kt_js_library with v1.9.0, but works fine with previous version (v1.8.1) #1096

Open
sudopk opened this issue Dec 22, 2023 · 0 comments

Comments

@sudopk
Copy link

sudopk commented Dec 22, 2023

With 1.9.0:

# https://github.com/bazelbuild/rules_kotlin
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "rules_kotlin",
    sha256 = "5766f1e599acf551aa56f49dab9ab9108269b03c557496c54acaf41f98e2b8d6",
    url = "https://github.com/bazelbuild/rules_kotlin/releases/download/v1.9.0/rules_kotlin-v1.9.0.tar.gz",
)

load("@rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "versions")

KOTLINC_VERSION = versions.KOTLIN_CURRENT_COMPILER_RELEASE.version

print("Kotlinc version: %s" % KOTLINC_VERSION)

kotlin_repositories()  # if you want the default. Otherwise see custom kotlinc distribution below

load("@rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")

kt_register_toolchains()  # to use the default toolchain, otherwise see toolchains below

I am using a dependency (any deps will do) via rules_jvm_external (version is immaterial, but i am using 5.3):

"org.jetbrains.kotlinx:kotlinx-html-js:0.6.12",

Then with rules:

load("@rules_kotlin//kotlin:js.bzl", "kt_js_import", "kt_js_library")
load("@rules_jvm_external//:defs.bzl", "artifact")

kt_js_library(
    name = "js",
    srcs = ["MyWhateverJs.kt"],
    deps = [
        ":kotlinx_html_js",
    ],
)

kt_js_import(
    name = "kotlinx_html_js",
    jars = [
        artifact("org.jetbrains.kotlinx:kotlinx-html-js"),
    ],
)

Then following fails:

❯❯❯ bazel build //js:js
DEBUG: /usr/home/sudopk/IdeaProjects/BazelWorkspace/WORKSPACE.bazel:18:6: Kotlinc version: 1.9.10
DEBUG: /home/sudopk/.cache/bazel/_bazel_sudopk/2eb1a85c08b2594eebc03baccb1b8f6f/external/rules_jvm_external~5.3/private/extensions/maven.bzl:141:14: The maven repository 'maven' is used in two different bazel modules, originally in '' and now in 'protobuf'
DEBUG: /home/sudopk/.cache/bazel/_bazel_sudopk/2eb1a85c08b2594eebc03baccb1b8f6f/external/rules_jvm_external~5.3/coursier.bzl:593:18: Found duplicate artifact versions
    com.google.code.gson:gson has multiple versions 2.8.6, 2.8.9
    com.google.guava:guava has multiple versions 30.0-jre, 31.1-jre
Please remove duplicate artifacts from the artifact list so you do not get unexpected artifact versions
INFO: Analyzed target //js:js (94 packages loaded, 4053 targets configured).
INFO: From Building external/rules_jvm_external~5.3/private/tools/java/com/github/bazelbuild/rules_jvm_external/librules_jvm_external.jar (4 source files) [for tool]:
warning: [options] source value 8 is obsolete and will be removed in a future release
warning: [options] target value 8 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
INFO: From Building external/rules_jvm_external~5.3/private/tools/java/com/github/bazelbuild/rules_jvm_external/zip/libzip.jar (1 source file) [for tool]:
warning: [options] source value 8 is obsolete and will be removed in a future release
warning: [options] target value 8 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
INFO: From Building external/rules_jvm_external~5.3/private/tools/java/com/github/bazelbuild/rules_jvm_external/jar/AddJarManifestEntry.jar (1 source file) [for tool]:
warning: [options] source value 8 is obsolete and will be removed in a future release
warning: [options] target value 8 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
ERROR: /usr/home/sudopk/IdeaProjects/BazelWorkspace/js/BUILD.bazel:6:14: Compiling Kotlin to JS //js:js { kt: 1 } failed: (Exit 1): build failed: error executing KotlinCompile command (from target //js:js) bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/rules_kotlin/src/main/kotlin/build '--flagfile=bazel-out/k8-fastbuild/bin/js/js.js-0.params'
error: could not find "/home/sudopk/.cache/bazel/_bazel_sudopk/2eb1a85c08b2594eebc03baccb1b8f6f/execroot/_main/./bazel-out/k8-fastbuild/bin/external/rules_jvm_external~5.3~maven~maven/v1/https/jcenter.bintray.com/org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/processed_kotlinx-html-js-0.6.12.jar" in [/home/sudopk/.cache/bazel/_bazel_sudopk/2eb1a85c08b2594eebc03baccb1b8f6f/execroot/_main]
exception: java.lang.IllegalStateException: FATAL ERROR: Could not find "/home/sudopk/.cache/bazel/_bazel_sudopk/2eb1a85c08b2594eebc03baccb1b8f6f/execroot/_main/./bazel-out/k8-fastbuild/bin/external/rules_jvm_external~5.3~maven~maven/v1/https/jcenter.bintray.com/org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/processed_kotlinx-html-js-0.6.12.jar" in [/home/sudopk/.cache/bazel/_bazel_sudopk/2eb1a85c08b2594eebc03baccb1b8f6f/execroot/_main]
	at org.jetbrains.kotlin.ir.backend.js.KlibKt$resolverLogger$1.fatal(klib.kt:114)
	at org.jetbrains.kotlin.library.KotlinLibrarySearchPathResolver.resolve(SearchPathResolver.kt:170)
	at org.jetbrains.kotlin.library.SearchPathResolver.resolve$default(SearchPathResolver.kt:19)
	at org.jetbrains.kotlin.library.SearchPathResolverKt.resolve(SearchPathResolver.kt:28)
	at org.jetbrains.kotlin.library.metadata.resolver.impl.KotlinLibraryResolverImpl$findLibraries$userProvidedLibraries$1.invoke(KotlinLibraryResolverImpl.kt:58)
	at org.jetbrains.kotlin.library.metadata.resolver.impl.KotlinLibraryResolverImpl$findLibraries$userProvidedLibraries$1.invoke(KotlinLibraryResolverImpl.kt:58)
	at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210)
	at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:170)
	at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:194)
	at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:809)
	at org.jetbrains.kotlin.library.metadata.resolver.impl.KotlinLibraryResolverImpl.findLibraries(KotlinLibraryResolverImpl.kt:59)
	at org.jetbrains.kotlin.library.metadata.resolver.impl.KotlinLibraryResolverImpl.resolveWithoutDependencies(KotlinLibraryResolverImpl.kt:40)
	at org.jetbrains.kotlin.backend.common.CommonJsKLibResolver.resolveWithoutDependencies(CommonJsKLibResolver.kt:51)
	at org.jetbrains.kotlin.ir.backend.js.ModulesStructure.<init>(klib.kt:486)
	at org.jetbrains.kotlin.ir.backend.js.PrepareAnalyzedSourceModuleKt.prepareAnalyzedSourceModule(prepareAnalyzedSourceModule.kt:28)
	at org.jetbrains.kotlin.ir.backend.js.PrepareAnalyzedSourceModuleKt.prepareAnalyzedSourceModule$default(prepareAnalyzedSourceModule.kt:17)
	at org.jetbrains.kotlin.cli.js.K2JsIrCompiler.processSourceModule(K2JsIrCompiler.kt:425)
	at org.jetbrains.kotlin.cli.js.K2JsIrCompiler.doExecute(K2JsIrCompiler.kt:276)
	at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:181)
	at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:72)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:100)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:46)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:79)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:40)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.bazel.kotlin.builder.toolchain.KotlinToolchain$KotlinCliToolInvoker.compile(KotlinToolchain.kt:213)
	at io.bazel.kotlin.builder.tasks.js.Kotlin2JsTaskExecutor$compile$2.invoke(Kotlin2JsTaskExecutor.kt:63)
	at io.bazel.kotlin.builder.tasks.js.Kotlin2JsTaskExecutor$compile$2.invoke(Kotlin2JsTaskExecutor.kt:63)
	at io.bazel.kotlin.builder.toolchain.CompilationTaskContext.executeCompilerTask(CompilationTaskContext.kt:126)
	at io.bazel.kotlin.builder.toolchain.CompilationTaskContext.executeCompilerTask$default(CompilationTaskContext.kt:118)
	at io.bazel.kotlin.builder.tasks.js.Kotlin2JsTaskExecutor.compile(Kotlin2JsTaskExecutor.kt:63)
	at io.bazel.kotlin.builder.tasks.js.Kotlin2JsTaskExecutor.execute(Kotlin2JsTaskExecutor.kt:32)
	at io.bazel.kotlin.builder.tasks.KotlinBuilder.executeJsTask(KotlinBuilder.kt:173)
	at io.bazel.kotlin.builder.tasks.KotlinBuilder.build(KotlinBuilder.kt:104)
	at io.bazel.kotlin.builder.tasks.CompileKotlin.invoke(CompileKotlin.kt:27)
	at io.bazel.worker.PersistentWorker$workTo$1.invoke(PersistentWorker.kt:97)
	at io.bazel.worker.PersistentWorker$workTo$1.invoke(PersistentWorker.kt:97)
	at io.bazel.worker.WorkerContext$TaskContext.resultOf(WorkerContext.kt:128)
	at io.bazel.worker.WorkerContext.doTask(WorkerContext.kt:156)
	at io.bazel.worker.PersistentWorker$start$1$1$producer$1$1.invoke$lambda$0(PersistentWorker.kt:70)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

Dec 21, 2023 5:14:42 PM worker request 0
SEVERE: Compilation failure: compile phase failed:Target //js:js failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 20.494s, Critical Path: 0.68s
INFO: 9 processes: 3 internal, 3 linux-sandbox, 3 worker.
ERROR: Build did NOT complete successfully

The file actually exists:

❯❯❯ ls -la /home/sudopk/.cache/bazel/_bazel_sudopk/2eb1a85c08b2594eebc03baccb1b8f6f/execroot/_main/./bazel-out/k8-fastbuild/bin/external/rules_jvm_external~5.3~maven~maven/v1/https/jcenter.bintray.com/org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/processed_kotlinx-html-js-0.6.12.jar
-r-xr-xr-x 1 sudopk primarygroup 232107 Dec 21 17:14 /home/sudopk/.cache/bazel/_bazel_sudopk/2eb1a85c08b2594eebc03baccb1b8f6f/execroot/_main/./bazel-out/k8-fastbuild/bin/external/rules_jvm_external~5.3~maven~maven/v1/https/jcenter.bintray.com/org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/processed_kotlinx-html-js-0.6.12.jar

Not sure if it is Kotlin IR backend issue or we are not setting some search path appropriately. But it works with kotlin_rules version v1.8.1 i.e. just replace the above http_archive with:

http_archive(
    name = "rules_kotlin",
    sha256 = "a630cda9fdb4f56cf2dc20a4bf873765c41cf00e9379e8d59cd07b24730f4fde",
    url = "https://github.com/bazelbuild/rules_kotlin/releases/download/v1.8.1/rules_kotlin_release.tgz",
)

Then:

❯❯❯ bazel build //js:js
DEBUG: /usr/home/sudopk/IdeaProjects/BazelWorkspace/WORKSPACE.bazel:17:6: Kotlinc version: 1.8.21
INFO: Analyzed target //js:js (93 packages loaded, 4051 targets configured).
INFO: From Compiling Kotlin to JS //js:js { kt: 1 }:
warning: ==========
This project currently uses the Kotlin/JS Legacy compiler backend, which has been deprecated and will be removed in a future release.

Please migrate your project to the new IR-based compiler (https://kotl.in/jsir).
Because your build tool will not support the new Kotlin/JS compiler, you will also need to migrate to Gradle.

You can continue to use the deprecated legacy compiler in the current version of the toolchain by providing the compiler option -Xuse-deprecated-legacy-compiler.
==========
INFO: Found 1 target...
Target //js:js up-to-date:
  bazel-bin/js/js.js
  bazel-bin/js/js.js.map
INFO: Elapsed time: 6.354s, Critical Path: 3.93s
INFO: 5 processes: 4 internal, 1 worker.
INFO: Build completed successfully, 5 total actions

This search result is somewhat related: https://youtrack.jetbrains.com/issue/KT-49894

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

2 participants