System-wide Installation of Gradle and JDK

Hi all,

these days I mostly write code for the JVM using the gradle build system.
When I setup my laptop with NixOS I just wanted to install the JDK and gradle system-wide, e.g. in /etc/nixos/configuration.nix. Tbh, I just found this easier than fiddling around with nix-shell (which I want to learn a bit later once I get to speed with NixOS).
Installing gradle and the JDK is fairly easy, however, a dependency of the project needs JDK 11 or higher - so I added gradle and jdk14 to my systemPackages only to find out that gradle uses a different version of Java, which in this case is Java 8 - and now loading the dependencies classes on runtime fails. After googling for a while I’m almost certain that I need to use the Overlay mechanism.

My question now is how I can solve the problem with gradle precisely - I think I need an overlay for gradle and override it’s build inputs. Sadly, I don’t know enough about Overlays at the moment to write this overlay on my own.

Can anyone provide a hint for me?
I’m thankful for every advice :slight_smile:

Thanks for reading this!

Overlays are useful if you want to change something in pkgs but they are not strictly necessary for this use case – you can just override gradle in place.

Looking at

that would probably be something like

environment.systemPackages = [
  ((pkgs.gradleGen.override {
    java = jdk15;

I do not see jdk14 in all-packages.nix, though.


Thank you very much for your post!
It isn’t only the correct solution for my specific problem, as it also shows that I confuse overrides with overlays and now I know what to learn next :slight_smile:

Thanks you much, this works well.