@@ -10,6 +10,7 @@ import org.gradle.api.plugins.JavaPluginConvention
1010import org.gradle.api.tasks.compile.GroovyCompile
1111import org.gradle.api.tasks.compile.JavaCompile
1212import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
13+ import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
1314import org.slf4j.Logger
1415import org.slf4j.LoggerFactory
1516import java.io.File
@@ -53,18 +54,30 @@ class JavaCrossCompilePlugin : Plugin<Project> {
5354 private fun JavaVersion.locate (): JavaLocation {
5455 logger.debug(" Locating JDK for $this " )
5556 val jdkHome = providers
56- .map { it.provide(this ) }
57- .firstOrNull() ? : throw cannotLocate()
57+ .firstNotNullResult {
58+ val jdkHome = it.provide(this )
59+ if (jdkHome == null ) {
60+ logger.debug(" Provider $it did not find a JDK" )
61+ null
62+ } else {
63+ logger.debug(" Provider $it found a JDK at $jdkHome " )
64+ jdkHome
65+ }
66+ } ? : throw cannotLocate()
5867 logger.debug(" Found JDK for $this at $jdkHome " )
5968 val runtimeJars = listOf (
6069 File (jdkHome, RT_JAR_PATH ),
6170 File (jdkHome, CLASSES_JAR_PATH )
6271 )
6372 val bootClasspath = runtimeJars
64- .firstOrNull {
65- val exists = it.exists()
66- if (exists) logger.debug(" Found runtime classes jar $it " ) else logger.debug(" Runtime classes jar $it does not exist" )
67- exists
73+ .firstNotNullResult {
74+ if (it.exists()) {
75+ logger.debug(" Found runtime classes jar $it " )
76+ it
77+ } else {
78+ logger.debug(" Runtime classes jar $it does not exist" )
79+ null
80+ }
6881 } ? : throw cannotLocate()
6982 return JavaLocation (jdkHome, bootClasspath.absolutePath)
7083 }
0 commit comments