How to specify the Java version?
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.
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.
I got it to work now, thanks. Feel free to close this issue if you don't think adding buildJdk is necessary.
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
I went with an overlay:
let
nixpkgs = import <nixpkgs> {
overlays = [(self: super: {jdk = super.jdk12;} )];
};
buildGradle = nixpkgs.callPackage ./gradle-env.nix {};
in
buildGradle {
}
I think the two easiest paths to resolving this issue are:
- Add an attribute to
buildGradlefor the java version (i.e. just plumb throughjavatogradleGenif it's set) - 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.