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

Tests which use java stub template with large classpaths fails because of local_jdk implicit dependency #6955

Closed
ittaiz opened this issue Dec 18, 2018 · 18 comments
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-Java Issues for Java rules type: bug

Comments

@ittaiz
Copy link
Member

ittaiz commented Dec 18, 2018

Description of the problem / feature request:

Running a java_test (we're actually using scala_junit_test but that uses the java_stub_template.txt) with a very long classpath fails since the template assumes existence of local_jdk/bin/jar in runfiles.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

I'll try to work on a full repro but given a target with a very long classpath using the java_stub_template (java_test/ scala_junit_test) try to test it with bazel 0.19.0 (maybe reproduces earlier) and it will fail with .../foo.runfiles/local_jdk/bin/jar: No such file or directory

I've worked around it for now by adding the following data dependency explicitly: "@bazel_tools//tools/jdk:jar",.
This generates a warning about using a deprecated dependency.

What operating system are you running Bazel on?

OS X

What's the output of bazel info release?

release 0.19.0

Have you found anything relevant by searching the web?

java_stub_template relevant line:

create_and_run_classpath_jar "local_jdk/bin/jar"

I think this is related to @cushon's work on #5594

@ittaiz
Copy link
Member Author

ittaiz commented Dec 18, 2018

cc @meisterT

@meisterT
Copy link
Member

cc @iirina

@irengrig irengrig added P1 I'll work on this now. (Assignee required) team-Rules-Java Issues for Java rules untriaged labels Dec 18, 2018
@cushon
Copy link
Contributor

cushon commented Dec 18, 2018

@laszlocsomor @meteorcloudy

I thought we were only using the classpath jar hack on windows, but that changed in 102ce6d because not all JDKs support @argument files. Note that OpenJDK 9 and newer do support parameter files, so there's a more principled fix available in that case: #6354

@cushon cushon removed their assignment Dec 18, 2018
@ittaiz
Copy link
Member Author

ittaiz commented Dec 18, 2018 via email

@ittaiz
Copy link
Member Author

ittaiz commented Jan 6, 2019

any thoughts? also #6354 is still open

@laszlocsomor
Copy link
Contributor

I'm not a domain expert, but I think Bazel could set JARBIN akin to JAVABIN as it does here:

# Set JAVABIN to the path to the JVM launcher.
%javabin%

Substitution.of(
"%javabin%",
JavaCommon.getJavaBinSubstitutionFromJavaExecutable(ruleContext, javaExecutable)));

@beala-stripe
Copy link

beala-stripe commented Jan 24, 2019

I have also run into this issue in a java_binary rule while setting the --javabase and --host_javabase to a custom target (an Azul JDK8). Thankfully @ittaiz's workaround worked (adding a data dep to the target: data = ["@local_jdk//:bin/jar"])

@ittaiz
Copy link
Member Author

ittaiz commented Feb 18, 2019

Any news about this?

@beala-stripe
Copy link

I'm also eager for a fix for this. Although adding the data dep gets the build working, I worry that depending on the local jdk negatively affects caching.

@lberki lberki added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged P1 I'll work on this now. (Assignee required) labels Mar 13, 2019
@ittaiz
Copy link
Member Author

ittaiz commented Mar 20, 2019

@cushon @laszlocsomor's suggestion sounds really reasonable and small. WDYT?
An even simpler (but hackier) solution can be to get the parent directory of JAVABIN and then append jar to it.

ittaiz added a commit to wix-incubator/rules_scala that referenced this issue Mar 21, 2019
Work around and somewhat prepare for resolution of
bazelbuild/bazel#6955
ittaiz added a commit to wix-incubator/rules_scala that referenced this issue Mar 21, 2019
Work around and somewhat prepare for resolution of
bazelbuild/bazel#6955
@ittaiz
Copy link
Member Author

ittaiz commented Mar 22, 2019

@cushon @lberki I've implemented the above in rules_scala (copied the stub template file).
WDYT? We need this in many more places and don't want to use the deprecated local_jdk.

ittaiz added a commit to bazelbuild/rules_scala that referenced this issue Mar 27, 2019
Work around and somewhat prepare for resolution of
bazelbuild/bazel#6955
@ittaiz
Copy link
Member Author

ittaiz commented Mar 27, 2019

@cushon @lberki wdyt?

johnynek pushed a commit to bazelbuild/rules_scala that referenced this issue Mar 27, 2019
* Use jar from java runtime and not local_jdk
Work around and somewhat prepare for resolution of
bazelbuild/bazel#6955

* use stub template from an http_archive

* remove unused symbol
@ittaiz
Copy link
Member Author

ittaiz commented May 21, 2019

Any news?

@joshrosen-stripe
Copy link
Contributor

joshrosen-stripe commented May 21, 2019

Maybe we should submit a PR to more clearly show the effective diff? As it stands now, this discussion links to PRs against bazelbuild/rules_scala and in that PR it's a little tricky to see the actual net change because it duplicates the entire java stub template. If we submitted a PR directly against bazelbuild/bazel then it might be easier to reason about exactly what's being proposed.

@iirina
Copy link
Contributor

iirina commented Sep 12, 2019

@ittaiz is this still happening?

@TheImplementer
Copy link

We've bumped into this issue as well, it looks like it's still happening. (bazel v2.2.0)

@ittaiz
Copy link
Member Author

ittaiz commented Jul 13, 2022

I think (not 100% sure) that @katre's fix solved the issue.

#11179

@hvadehra
Copy link
Member

Closing based on recent comments, please re-open if the issue persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-Java Issues for Java rules type: bug
Projects
None yet
Development

No branches or pull requests