Skip to content

Commit

Permalink
Compare bin subdirs of java home on root mismatch [fix 187] (#240)
Browse files Browse the repository at this point in the history
* Compare only bin subdirs of java home [fix 187]

* use bin subdir matcing only as a fallback
  • Loading branch information
Rattenkrieg authored Jan 18, 2023
1 parent 96719d2 commit f2c6242
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions doctor-plugin/src/main/java/com/osacky/doctor/JavaHomeCheck.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class JavaHomeCheck(
if (extension.javaHomeHandler.ensureJavaHomeMatches.get() && !isGradleUsingJavaHome()) {
val message = buildString {
appendln("Gradle is not using JAVA_HOME.")
appendln("JAVA_HOME is ${environmentJavaHome?.toFile()?.toPath()?.toAbsolutePath()}")
appendln("Gradle is using ${gradleJavaHome.toPath().toAbsolutePath()}")
appendln("JAVA_HOME is ${environmentJavaHome?.toFile()?.toPath()?.toRealPath()}")
appendln("Gradle is using ${gradleJavaHome.toPath().toRealPath()}")
appendln("This can slow down your build significantly when switching from Android Studio to the terminal.")
appendln("To fix: Project Structure -> JDK Location.")
appendln("Set this to your JAVA_HOME.")
Expand All @@ -66,8 +66,12 @@ class JavaHomeCheck(

private fun isGradleUsingJavaHome(): Boolean {
// Follow symlinks when checking that java home matches.
if (environmentJavaHome != null && gradleJavaHome.toPath().toRealPath() == File(environmentJavaHome).toPath().toRealPath()) {
return true
if (environmentJavaHome != null) {
val gradleJavaHomePath = gradleJavaHome.toPath()
val environmentJavaHomePath = File(environmentJavaHome).toPath()
if (gradleJavaHomePath.toRealPath() != environmentJavaHomePath.toRealPath()) {
return gradleJavaHomePath.toRealPath().resolve("bin") == environmentJavaHomePath.resolve("bin").toRealPath()
}
}
return false
}
Expand Down

0 comments on commit f2c6242

Please sign in to comment.