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

Failed to find javaparser in runfiles #211

Closed
KrisJohnstone opened this issue Oct 1, 2023 · 16 comments · Fixed by #216
Closed

Failed to find javaparser in runfiles #211

KrisJohnstone opened this issue Oct 1, 2023 · 16 comments · Fixed by #216

Comments

@KrisJohnstone
Copy link

Attempting to convert a project and am getting a javaparser error.

Expected Outcome:
(At the very least a migrated listed of maven dependencies)

Actual Outcome:
11:03PM FTL external/contrib_rules_jvm/java/gazelle/configure.go:133 > could not start javaparser error="failed to start / connect to javaparser server: failed to find javaparser in runfiles"

Files/Stepts to Reproduce:
Workspace:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "io_bazel_rules_go",
    sha256 = "278b7ff5a826f3dc10f04feaf0b70d48b68748ccd512d7f98bf442077f043fe3",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.41.0/rules_go-v0.41.0.zip",
        "https://github.com/bazelbuild/rules_go/releases/download/v0.41.0/rules_go-v0.41.0.zip",
    ],
)

http_archive(
    name = "bazel_gazelle",
    sha256 = "d3fa66a39028e97d76f9e2db8f1b0c11c099e8e01bf363a923074784e451f809",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.33.0/bazel-gazelle-v0.33.0.tar.gz",
        "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.33.0/bazel-gazelle-v0.33.0.tar.gz",
    ],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")

go_rules_dependencies()

go_register_toolchains(version = "1.20.5")

gazelle_dependencies()

http_archive(
    name = "contrib_rules_jvm",
    sha256 = "bd0f82def1879df85ff0a80767e6455911e1c9c1eac5db1de8f68dcccd4a3d7a",
    strip_prefix = "rules_jvm-0.18.0",
    url = "https://github.com/bazel-contrib/rules_jvm/releases/download/v0.18.0/rules_jvm-v0.18.0.tar.gz",
)

load("@contrib_rules_jvm//:repositories.bzl", "contrib_rules_jvm_deps")

contrib_rules_jvm_deps()

load("@contrib_rules_jvm//:setup.bzl", "contrib_rules_jvm_setup")

contrib_rules_jvm_setup()

load("@contrib_rules_jvm//:setup.bzl", "contrib_rules_jvm_setup")

contrib_rules_jvm_setup()

load("@contrib_rules_jvm//:repositories.bzl", "contrib_rules_jvm_deps", "contrib_rules_jvm_gazelle_deps")

contrib_rules_jvm_deps()

contrib_rules_jvm_gazelle_deps()

load("@contrib_rules_jvm//:setup.bzl", "contrib_rules_jvm_setup")

contrib_rules_jvm_setup()

load("@contrib_rules_jvm//:gazelle_setup.bzl", "contrib_rules_jvm_gazelle_setup")

contrib_rules_jvm_gazelle_setup()

http_archive(
    name = "com_google_protobuf",
    sha256 = "a79d19dcdf9139fa4b81206e318e33d245c4c9da1ffed21c87288ed4380426f9",
    strip_prefix = "protobuf-3.11.4",
    urls = [
        "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.11.4.tar.gz",
        "https://github.com/protocolbuffers/protobuf/archive/v3.11.4.tar.gz",
    ],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

BUILD file:

load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")

gazelle(
    name = "gazelle",
    gazelle = ":gazelle_bin",
)

gazelle_binary(
    name = "gazelle_bin",
    languages = DEFAULT_LANGUAGES + [
        "@contrib_rules_jvm//java/gazelle",
    ],
)

Output of bazel build:

bazel build //:gazelle_bin
INFO: Analyzed target //:gazelle_bin (15 packages loaded, 1187 targets configured).
INFO: Found 1 target...
Target //:gazelle_bin up-to-date:
  bazel-bin/gazelle_bin_/gazelle_bin
INFO: Elapsed time: 9.545s, Critical Path: 5.50s
INFO: 84 processes: 3 internal, 70 darwin-sandbox, 11 worker.
INFO: Build completed successfully, 84 total actions

Full Error:

bazel run //:gazelle
INFO: Analyzed target //:gazelle (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:gazelle up-to-date:
  bazel-bin/gazelle-runner.bash
  bazel-bin/gazelle
INFO: Elapsed time: 0.191s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/gazelle
11:03PM FTL external/contrib_rules_jvm/java/gazelle/configure.go:133 > could not start javaparser error="failed to start / connect to javaparser server: failed to find javaparser in runfiles"
@stevebarrau
Copy link
Collaborator

Can you share your version of Bazel and ideally a repo with a repro?

@KrisJohnstone
Copy link
Author

Can you share your version of Bazel and ideally a repo with a repro?

I've tried 6.3.0, 6.1.0 and 5.4.1.

I've been able to replicate here:
https://github.com/KrisJohnstone/spring-petclinic/tree/bazel-example

@stevebarrau
Copy link
Collaborator

Thanks for the repro repo. I get the same error as you.

This looks like an issue with our use of FindBinary here:

javaParserPath, found := bazel.FindBinary("java/src/com/github/bazel_contrib/contrib_rules_jvm/javaparser/generators", "Main")

Hardcoding javaParserPath to "external/contrib_rules_jvm/java/src/com/github/bazel_contrib/contrib_rules_jvm/javaparser/generators/Main" works is your case (and you could patch this in until we find a solution) but this will not work long term I imagine.

I will try to have a look at what is going on this week.

@KrisJohnstone
Copy link
Author

KrisJohnstone commented Oct 19, 2023

That worked a treat. Thanks @stevebarrau

EDIT: Did you want me to close this Issue or leave it open for the fix?

@stevebarrau
Copy link
Collaborator

@KrisJohnstone can you give #216 a try and see if this resolve this issue?

@KrisJohnstone
Copy link
Author

I get the following weirdly:

/private/var/tmp/_bazel_krisjohnstone/3337dddeaeeddd03860ac735ca6cd027/execroot/main/bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/contrib_rules_jvm/java/src/com/github/bazel_contrib/contrib_rules_jvm/javaparser/generators/Main: Cannot locate runfiles directory. (Set $JAVA_RUNFILES to inhibit searching.)
10:28PM FTL external/contrib_rules_jvm/java/gazelle/configure.go:133 > could not start javaparser error="failed to start / connect to javaparser server: failed to read port from javaparser server - maybe it crashed: timed out waiting for port file to be written by javaparser server"

@gkze
Copy link

gkze commented Oct 25, 2023

Same here - after trying #216

@ar3s3ru
Copy link
Contributor

ar3s3ru commented Nov 10, 2023

Same here too with #216. I will add: I'm using Bzlmod.

/private/var/tmp/_bazel_ar3s3ru/3efe07ce4123e4dfef2f8db5ddd896ff/execroot/_main/bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/contrib_rules_jvm~override/java/src/com/github/bazel_contrib/contrib_rules_jvm/javaparser/generators/Main: Cannot locate runfiles directory. (Set $JAVA_RUNFILES to inhibit searching.)
8:46AM FTL external/contrib_rules_jvm~override/java/gazelle/configure.go:133 > could not start javaparser error="failed to start / connect to javaparser server: failed to read port from javaparser server - maybe it crashed: timed out waiting for port file to be written by javaparser server"
Error: bazel exited with exit code: 1

@jtcarnes
Copy link

I'll say I'm using bzlmod as well and am hitting the same issue. Mine is for using the gazelle plugin, but the error is the same.

For reproducibility:

bazelrc:

common --java_language_version=remotejdk_11 --tools_java_runtime_version=remotejdk_11 --tool_java_language_version=11

MODULE.bazel

module(name = "test")

bazel_dep(name = "gazelle", version = "0.34.0")
bazel_dep(name = "contrib_rules_jvm", version = "0.18.0")

BUILD.bazel:

load("@gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
gazelle(
    name = "gazelle",
    gazelle = ":gazelle_bin",
)

gazelle_binary(
    name = "gazelle_bin",
    languages = DEFAULT_LANGUAGES + [
        "@contrib_rules_jvm//java/gazelle",
    ],
)

Running Gazelle:

bazel run //:gazelle                                                                                                                                                                                                                                              ✔ 
INFO: Analyzed target //:gazelle (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:gazelle up-to-date:
  bazel-bin/gazelle-runner.bash
  bazel-bin/gazelle
INFO: Elapsed time: 0.039s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/gazelle
2:09PM FTL external/contrib_rules_jvm~0.18.0/java/gazelle/configure.go:133 > could not start javaparser error="failed to start / connect to javaparser server: failed to find javaparser in runfiles"

@ar3s3ru
Copy link
Contributor

ar3s3ru commented Dec 6, 2023

I've opened #224 to fix the issue with locating javaparser.

However, in my specific case, I'm hitting a different error now: Cannot locate runfiles directory.

Can some of you try on your side my branch version and report if you're hitting the same issue?

You can use the following override if you're on Bzlmod

git_override(
    module_name = "contrib_rules_jvm",
    remote = "https://github.com/ar3s3ru/rules_jvm",
    commit = "b01bab003632dc0624a4e8ff1d4354881ee95a7c",
)

Some details on my local project:

  • Bazel: 6.4.0
  • Bzlmod on

Error output:

Loading: 
Loading: 
Loading: 0 packages loaded
Analyzing: target //:gazelle (0 packages loaded, 0 targets configured)
INFO: Analyzed target //:gazelle (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
[0 / 7] [Prepa] BazelWorkspaceStatusAction stable-status.txt
Target //:gazelle up-to-date:
  bazel-bin/gazelle-runner.bash
  bazel-bin/gazelle
INFO: Elapsed time: 1.315s, Critical Path: 1.16s
INFO: 3 processes: 1 internal, 2 darwin-sandbox.
INFO: Build completed successfully, 3 total actions
INFO: Running command line: bazel-bin/gazelle
�[90m2:07PM�[0m �[32mINF�[0m �[1mexternal/contrib_rules_jvm~override/java/gazelle/private/servermanager/servermanager.go:70�[0m�[36m >�[0m starting javaparser with command �[36mcmd=�[0m"/private/var/tmp/_bazel_ar3s3ru/3efe07ce4123e4dfef2f8db5ddd896ff/execroot/_main/bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/contrib_rules_jvm~override/java/src/com/github/bazel_contrib/contrib_rules_jvm/javaparser/generators/Main --jvm_flag=-Dorg.slf4j.simpleLogger.defaultLogLevel=info --server-port-file-path /var/folders/dg/jf2qkwmn0qg4qklxq9c84j0w0000gn/T/gazelle-javaparser1138877067/port --workspace /Users/ar3s3ru/Code/*** --idle-timeout 30"
/private/var/tmp/_bazel_ar3s3ru/3efe07ce4123e4dfef2f8db5ddd896ff/execroot/_main/bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/contrib_rules_jvm~override/java/src/com/github/bazel_contrib/contrib_rules_jvm/javaparser/generators/Main: Cannot locate runfiles directory. (Set $JAVA_RUNFILES to inhibit searching.)
�[90m2:07PM�[0m �[1m�[31mFTL�[0m�[0m �[1mexternal/contrib_rules_jvm~override/java/gazelle/configure.go:133�[0m�[36m >�[0m could not start javaparser �[36merror=�[0m�[31m"failed to start / connect to javaparser server: failed to read port from javaparser server - maybe it crashed: timed out waiting for port file to be written by javaparser server"�[0m
Error: bazel exited with exit code: 1

@ar3s3ru
Copy link
Contributor

ar3s3ru commented Dec 7, 2023

Seems like the error I was mentioning above was happening since JAVA_RUNFILES was not being passed to the javaparser/generators/Main's java_binary invoked by Gazelle's plugin, due to this: https://github.com/bazelbuild/bazel/blob/492ee4c91b507bc07f63da1bafa1696cbcf75bd2/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt#L185

(More context here: https://bazelbuild.slack.com/archives/C01HMGN77Q8/p1701887957242259)

My latest commit apparently fixes that, at least on my private repro project: b01bab0

illicitonion pushed a commit that referenced this issue Dec 13, 2023
This should resolve #211 for good.

The java dependencies changes are caused by a run of ./tools/update-dependencies.sh.

Co-authored-by: Danilo Cianfrone <[email protected]>
@misberner
Copy link

Great to see this is fixed! 🎉 Is there already a plan for when a new release including this will get cut?

@illicitonion
Copy link
Collaborator

I just released v0.20.0 including this fix.

@misberner
Copy link

Amazing, thanks for the quick turnaround on this!

@ar3s3ru
Copy link
Contributor

ar3s3ru commented Jan 4, 2024

@illicitonion I don't see that version in BCR 👀

@illicitonion
Copy link
Collaborator

It looks like we don't have automatic BCR mirroring enabled - you can following along at bazelbuild/bazel-central-registry#1268 to see how our progress at getting automatic mirroring working goes.

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

Successfully merging a pull request may close this issue.

7 participants