diff --git a/changelog/@unreleased/pr-184.yml b/changelog/@unreleased/pr-184.yml new file mode 100644 index 00000000..eb644985 --- /dev/null +++ b/changelog/@unreleased/pr-184.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: Use bin/javac to find JAVA_HOME instead of bin/java to avoid accidentally installing a JRE instead of a JDK. + links: + - https://github.com/palantir/gradle-jdks/pull/184 diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkManager.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkManager.java index f984e443..0a26f702 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkManager.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkManager.java @@ -194,7 +194,7 @@ private Path findJavaHome(Path 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()))) + && file.endsWith(Paths.get("bin", SystemTools.javac()))) .findFirst() // JAVA_HOME/bin/java .orElseThrow(() -> new RuntimeException("Failed to find java home in " + temporaryJdkPath)) diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/SystemTools.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/SystemTools.java index 9bec56db..cc05bb01 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/SystemTools.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/SystemTools.java @@ -26,6 +26,13 @@ static String java() { return "java"; } + static String javac() { + if (Os.current() == Os.WINDOWS) { + return "javac.exe"; + } + return "javac"; + } + static String keytool() { if (Os.current() == Os.WINDOWS) { return "keytool.exe";