-
Notifications
You must be signed in to change notification settings - Fork 66
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
Difficult to override remote JDKs when using Bzlmod #222
Comments
Your |
Sorry, this was my mistake constructing the snippet. There was a Edit: just in case it's a version thing, the actual file looks closer to: use_repo(custom_java_repositories, "jdk11", "jdk17", "jdk21")
register_toolchains(
"@jdk11//:all",
"@jdk17//:all",
"@jdk21//:all",
) |
Cc @hvadehra |
Could you post the output of running with |
Log from the main project is incredibly spammy (and has other problems) so I made a small minimal reproduction. For convenience, it just uses the downloader config to block access to Attached are the logs from running Hopefully this is helpful! |
Thanks, this appears to work in the minimal case. I'll port it over to the original project and report back 🤞 |
Edit: fixed it, was entirely an error on my part! I'd typed Quick update: although it's playing nicely with the example repository, it's not behaving in the main project. Trying to investigate why, because I can't see anything obviously different. I'm assuming one of the other rules that is being pulled in is causing some kind of conflict, so I'll do a bit more digging. Another minor observation is that if I no disable bzlmod on the example repository, it fails to build. I'm not too bothered about this, but I find it interesting that the behaviour appears to differ depending on how the rules are being loaded? Update: running with
Not sure why it's being accepted at first and then rejected later. Continuing to investigate! |
@hvadehra just to confirm, this appears to all be working now. I'll leave the issue open for now, and if I have some free time at the end of the week I'll look at raising a PR with some Bzlmod examples if you think that would be helpful. Thanks! |
This was an incredibly helpful example for me. Thanks! |
I stumbled on this after having some difficulty with registering a java toolchain. Would someone mind posting a complete example? I've done something like...
and then in MODULE.bazel:
This gets me a runtime java toolchain but no JDK toolchain. Adding
When I inspect the archive, however, it seems to be structurally similar to other packages (eg. zulu) I can find. Anyways, a full example would be much appreciated! |
At a guess, I think this is roughly what you want (minus the error, of course). From the stack you posted, it seems that it's failing whilst attempting to register the toolchain, due to not finding
What happens if you change this as per the comment, i.e.
I just had a quick nosey at the OSX package for Zulu 21, and I think the key difference is that one has a set of symlinks at the defined content root, whilst the Hostpot archive that you're grabbing does not. |
A bit of background context: I'm trying to upgrade a project running in Bazel 6.5.0 to use more recent versions of, well, everything. Unfortunately, there's a lot of custom stuff in there that makes it less than trivial to just bump up version numbers. To try and simplify things, I'm looking to migrate the existing Bazel 6.5.0
WORKPSACE
file to have as much stuff inMODULE.bazel
as possible. Unfortunately,rules_java
is proving tricky...Expected behaviour: defining custom
remote_java_repositories
inMODULE.bazel
should prevent the defaultremotejdk...
repositories from being fetchedActual behaviour: the remote repositories (at least one) are still fetched
More details:
Currently, the version of
rules_java
is7.3.1
; I'm hesitant to update the version as some later versions require Bazel>= 7.0.0
andright now that version just doesn't work at all for me (although, then, some of the most recent drop the requirement back down to
>= 6.2.0
?). The originalWORKSPACE
file looked something like this (somewhat paraphrased for brevity):When I try and migrate this to bzlmod, I end up with something that looks like the following:
where
custom_java_repositories.bzl
is amodule_extension
that looks a bit like this:However,
rules_java
is still very insistent in attempting to downloadremotejdk21_linux
fromhttps://mirror.bazel.build/
, which doesn't work and causes the build to fail. I've seen some other issues talking about registering the custom toolchains earlier, but I don't think that's possible since@bazel_tools//tools/jdk:remote_java_repository
doesn't seem to work from within amodule_extension
.(Also, just in case it's relevant, the examples here specify
jdk11
, but I'm actually doing 11, 17, and 21.)I've also tried setting
--javabase=@jdk11//:jdk
(and--java_toolchain
and `--host_...) but they don't seen to have any effect.This is probably a "pebcak" error but it's tricky to work out what's going on without some Bzlmod examples / documentation. I'm hoping I'm just "doing it wrong" and that maybe there's a really obvious answer?
The text was updated successfully, but these errors were encountered: