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

How to specify the Java version? #11

Open
piegamesde opened this issue Mar 8, 2020 · 5 comments
Open

How to specify the Java version? #11

piegamesde opened this issue Mar 8, 2020 · 5 comments

Comments

@piegamesde
Copy link

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.

@tadfisher
Copy link
Owner

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.

@piegamesde
Copy link
Author

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

@euank
Copy link

euank commented May 18, 2020

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

@piegamesde
Copy link
Author

I went with an overlay:

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

@euank
Copy link

euank commented Jun 7, 2020

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.

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

No branches or pull requests

3 participants