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

java: set an additional JAVA_HOME per major version #76699

Closed
wants to merge 1 commit into from

Conversation

raboof
Copy link
Member

@raboof raboof commented Dec 30, 2019

This makes it easier to discover multiple JDK installations

Motivation for this change

This can be useful for builds that require multiple JDK versions to be available side-by-side.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @NeQuissimus @fpletz @edwtjo @volth @hlolli @taku0

This makes it easier to discover multiple JDK installations, which can be
required to be available side-by-side for some builds.
@NeQuissimus
Copy link
Member

I'd argue this is something non-standard you should set in your environment, not in the nixpkgs derivations. But I am open to discussions. I have never had to use variables like these (I go though different nix-shell invocations to build against multiple JDKs).

@raboof
Copy link
Member Author

raboof commented Dec 31, 2019

something non-standard you should set in your environment, not in the nixpkgs derivations

It's definitely a niche use case, but a google search for JAVA_8_HOME shows it's not entirely unheard of

I go though different nix-shell invocations to build against multiple JDKs

Yes, that is neater when possible. I have some builds that want to be able to find both JDK8 and JDK11 bootclasspaths during the same build (invocation/artifact), though, so that is where this would come in useful.

@taku0
Copy link
Contributor

taku0 commented Jan 5, 2020

Also adoptopenjdk-bin should be updated.

@jorsn
Copy link
Member

jorsn commented Apr 20, 2020

If you introduce JAVA_?_HOME into nix derivations, then you create another de-facto standard only for nixpkgs. If this is not a standard respected by java but something which completely depends on how you handle it in a specific build, then I think, this should be set only for this build. Or is there any formal/generally accepted standard for handling multiple JDKs in one build?

@raboof
Copy link
Member Author

raboof commented Apr 20, 2020

If you introduce JAVA_?_HOME into nix derivations, then you create another de-facto standard only for nixpkgs

I agree that's not great, though https://www.google.com/search?client=firefox-b-d&q=JAVA_8_HOME suggests it's already not entirely unheard of.

It's exotic, though, I agree - if there were some more widely used approach that would certainly be my preference.

Or is there any formal/generally accepted standard for handling multiple JDKs in one build?

Not as far as I know.

@jorsn
Copy link
Member

jorsn commented Apr 20, 2020

If you introduce JAVA_?_HOME into nix derivations, then you create another de-facto standard only for nixpkgs

I agree that's not great, though https://www.google.com/search?client=firefox-b-d&q=JAVA_8_HOME suggests it's already not entirely unheard of.

It's exotic, though, I agree - if there were some more widely used approach that would certainly be my preference.

Or is there any formal/generally accepted standard for handling multiple JDKs in one build?

Not as far as I know.

Then why should the Nix community standardize it? This would also need to be documented and enforced.

From the google search, my impression is that most of the time people set JAVA_HOME to $JAVA_?_HOME to switch between java versions. With nix builds, nix-shell or lorri(+direnv) it is easy to select the right JDK.

For your use case, @raboof (multiple JDKs at once): If there are the JAVA_?_HOMEs then you still need to tell your build to use them. So you need to be explicit again. What is the benefit from having a part of this abstracted in nixpkgs when a part of this is still needed in each build?
You can always set JAVA_?_HOME in any derivation that needs it.

Is this use case very common? Or is your proposal an abstraction of multiple use cases? Are there others than this which would benefit from your proposal?

Furthermore, why do you only assign JAVA_?_HOMEs for major releases? What if a build needs, say, openjdk8 from nixos-19.03, zulu8, openjdk12 and oraclejdk12? Is there a canonical way of naming the additional JAVA_?_HOMEs? Or how does nix decide which JAVA_{8,12}_HOME to choose? This is already a mess with JAVA_HOME depending on the order of evaluation of buildInputs, which isn't specified AFAIK. The solution I see is: Always have at most one JDK in buildInputs and be explicit about everything else.

@raboof
Copy link
Member Author

raboof commented Apr 20, 2020

Is this use case very common? Or is your proposal an abstraction of multiple use cases? Are there others than this which would benefit from your proposal?

I'll be the first to admit it's a somewhat niche situation, but it would definitely benefit other build tools and IDE's that allow 'interactively' switching between Java versions.

@asbachb
Copy link
Contributor

asbachb commented Jun 17, 2020

I guess I also agree with the voices against this change since it contributes to promote non standard environments. If it's for niche situations why this should be rolled out in general and not be solved in user space.

@raboof
Copy link
Member Author

raboof commented Jun 18, 2020

it contributes to promote non standard environments

i think there is a real need for a standard way to discover the available JDK's. There is no standard way to achieve this, and such a standard isn't going to materialize spontaneously - it should emerge from smaller experiments. This could be such a smaller experiment.

If it's for niche situations why this should be rolled out in general

I think one of the wonderful things of open source is that if someone cares enough about a certain niche, they can put in the work to have 'their' niche well-supported and contribute those improvements upstream. Having a single niche well-supported is of relatively little value, but accumulating and supporting many niches is an advantage for the project as a whole. Of course this has to be balanced against increased maintenance burden - but in this case I'd say that's pretty light.

Anyway, this PR has gained a conflict, closing for now.

@raboof raboof closed this Jun 18, 2020
Staging automation moved this from Needs review to Done Jun 18, 2020
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/auto-detecting-java-installations/4677/6

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

Successfully merging this pull request may close these issues.

None yet

6 participants