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

Support using the plugin with Java 8 #97

Open
fhoeben opened this issue Aug 13, 2022 · 2 comments · May be fixed by #184
Open

Support using the plugin with Java 8 #97

fhoeben opened this issue Aug 13, 2022 · 2 comments · May be fixed by #184

Comments

@fhoeben
Copy link

fhoeben commented Aug 13, 2022

What happened?

I tried to add the plugin to our project FitNesse. I added the plugin to the plugins block and added the following config

jdks {
  jdk(8) {
    distribution = 'azul-zulu'
    jdkVersion = '8.64.0.19'
  }
}

javaVersions {
  libraryTarget = 8
}

When I tried to build I got:

java.lang.UnsupportedClassVersionError: com/palantir/gradle/jdks/JdksPlugin 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
com/palantir/gradle/jdks/JdksPlugin 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

What did you want to happen?

I would have liked to be able to use this plugin also when my gradle is using Java 8

@arlaneenalra
Copy link

It looks like:

private Path findJavaHome(Path temporaryJdkPath) {
try (Stream<Path> files = Files.walk(temporaryJdkPath)) {
return files.filter(file -> Files.isRegularFile(file)
// macos JDKs have a `bin/java` symlink to `Contents/Home/bin/java`
&& !Files.isSymbolicLink(file)
&& file.endsWith(Paths.get("bin", SystemTools.java())))
.findFirst()
// JAVA_HOME/bin/java
.orElseThrow(() -> new RuntimeException("Failed to find java home in " + temporaryJdkPath))
// JAVA_HOME/bin
.getParent()
// JAVA_HOME
.getParent();
} catch (IOException e) {
throw new RuntimeException("Failed to find java home in " + temporaryJdkPath, e);
}
}
finds the bare JRE instead of the JDK

2023-04-02T17:27:21.811-0500 [INFO] [org.gradle.api.Project] Moving JDK azul-zulu 8.68.0.21-8.0.362 (999007504b0ffb2e) home /Users/jules/.gradle/gradle-jdks/azul-zulu-8.68.0.21-8.0.362-999007504b0ffb2e.in-progress-7bb4e4aa/zulu8.68.0.21-ca-jdk8.0.362-macosx_aarch64/zulu-8.jdk/Contents/Home/jre to /Users/jules/.gradle/gradle-jdks/azul-zulu-8.68.0.21-8.0.362-999007504b0ffb2e

I'm not entirely sure why .. but that's likely what's breaking things here ..

This code appears to be looking for java instead of javac

static String java() {
if (Os.current() == Os.WINDOWS) {
return "java.exe";
}
return "java";
}

Which seems to contribute to the problem... hmmm

arlaneenalra added a commit to arlaneenalra/gradle-jdks that referenced this issue Apr 2, 2023
There are some situations where using `bin/java` as a heuristic
to find JAVA_HOME within a JDK package can result in mistakenly
finding a JRE root instead. Looking for `bin/javac` fixes this
since JREs do not have `javac`.

This should fix palantir#97
@arlaneenalra arlaneenalra linked a pull request Apr 2, 2023 that will close this issue
jonahbeckford pushed a commit to jonahbeckford/gradle-jdks that referenced this issue Oct 6, 2023
There are some situations where using `bin/java` as a heuristic
to find JAVA_HOME within a JDK package can result in mistakenly
finding a JRE root instead. Looking for `bin/javac` fixes this
since JREs do not have `javac`.

This should fix palantir#97
@CRogers
Copy link
Contributor

CRogers commented Feb 12, 2024

java.lang.UnsupportedClassVersionError: com/palantir/gradle/jdks/JdksPlugin 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

This is saying the JDK you are running Gradle with is a Java 8 JDK, and this plugin (all our gradle plugins + libraries) require Java 11 to run. You'll need to upgrade to JDK you use (Java 8 has been end of life since 31 Mar 2022). Eventually we'll start requiring Java 17 for Gradle plugins and libraries.

An upcoming feature of this project will be managing the JDK used to run Gradle, which will make this much easier to roll out to users, as it will automatically install the right JDK even if they have no JDKs installed. I cannot give any definitive timeline when we actually get around to building that feature though, although we kinda need it soon internally.

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

Successfully merging a pull request may close this issue.

3 participants