gradle2nix icon indicating copy to clipboard operation
gradle2nix copied to clipboard

How to specify the Java version?

Open piegamesde opened this issue 5 years ago • 5 comments

I nixified my JavaFX application and when trying to build it I get java.lang.UnsupportedClassVersionError: org/openjfx/gradle/JavaFXPlugin has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0.

Using Gradle, everything runs fine, I also set the compatibility to JavaVersion.VERSION_11 which is version 55.

piegamesde avatar Mar 08 '20 23:03 piegamesde

When calling buildGradle, you need to override jdk in the nixpkgs environment, or to set JAVA_HOME in the build environment (e.g. in preBuild).

A more ergonomic way to do this would be to have a buildJdk argument or similar for gradle-env.nix.

tadfisher avatar Mar 09 '20 00:03 tadfisher

I got it to work now, thanks. Feel free to close this issue if you don't think adding buildJdk is necessary.

piegamesde avatar Mar 09 '20 22:03 piegamesde

It's probably worth documenting this; it took me a few tries to get a working override here.

Here's what I ended up with which worked for my derivation (where I needed to build with jdk11 but it was defaulting to jdk8):

{ callPackage, gradleGen, pkgs, ... }:
let
  buildGradle = callPackage ./gradle-env.nix {
    gradleGen = gradleGen.override {
      java = pkgs.jdk11;
    };
  };
in
buildGradle {
  envSpec = ./gradle-env.json;

  src = ./myProjectSrc;
  # ... etc
}

I'm curious if that's the same solution you ended up with, or a different one @piegamesde

euank avatar May 18 '20 06:05 euank

I went with an overlay:

let
	nixpkgs = import <nixpkgs> {
		overlays = [(self: super: {jdk = super.jdk12;} )];
	};
	buildGradle = nixpkgs.callPackage ./gradle-env.nix {};
in
buildGradle {
}

piegamesde avatar May 18 '20 10:05 piegamesde

I think the two easiest paths to resolving this issue are:

  1. Add an attribute to buildGradle for the java version (i.e. just plumb through java to gradleGen if it's set)
  2. Document overriding gradleGen for the java version somewhere. It looks like the readme is all the docs we've got here.

@tadfisher Do you have any opinion or other ideas here? I think 1 makes sense to me and I'm happy to open a PR if you'd like.

euank avatar Jun 07 '20 00:06 euank