Add a user-friendly report that the JDK tools are missing
Issue #KT-20214 Fixed
This commit is contained in:
+3
@@ -198,6 +198,9 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
|
|||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
open fun execute(inputs: IncrementalTaskInputs): Unit {
|
open fun execute(inputs: IncrementalTaskInputs): Unit {
|
||||||
|
// Check that the JDK tools are available in Gradle (fail-fast, instead of a fail during the compiler run):
|
||||||
|
findToolsJar()
|
||||||
|
|
||||||
val sourceRoots = getSourceRoots()
|
val sourceRoots = getSourceRoots()
|
||||||
val allKotlinSources = sourceRoots.kotlinSourceFiles
|
val allKotlinSources = sourceRoots.kotlinSourceFiles
|
||||||
|
|
||||||
|
|||||||
+15
-2
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.tasks
|
package org.jetbrains.kotlin.gradle.tasks
|
||||||
|
|
||||||
|
import org.gradle.api.GradleException
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.artifacts.Configuration
|
import org.gradle.api.artifacts.Configuration
|
||||||
import org.gradle.api.artifacts.ResolvedDependency
|
import org.gradle.api.artifacts.ResolvedDependency
|
||||||
@@ -86,8 +87,20 @@ internal fun findKotlinScriptJvmClasspath(project: Project): List<File> =
|
|||||||
internal fun findKotlinReflectClasspath(project: Project): List<File> =
|
internal fun findKotlinReflectClasspath(project: Project): List<File> =
|
||||||
findKotlinModuleJar(project, KOTLIN_REFLECT_EXPECTED_CLASS, KOTLIN_REFLECT)
|
findKotlinModuleJar(project, KOTLIN_REFLECT_EXPECTED_CLASS, KOTLIN_REFLECT)
|
||||||
|
|
||||||
internal fun findToolsJar(): File? =
|
internal fun findToolsJar(): File? {
|
||||||
Class.forName("com.sun.tools.javac.util.Context")?.let(::findJarByClass)
|
val javacUtilContextClass =
|
||||||
|
try {
|
||||||
|
Class.forName("com.sun.tools.javac.util.Context")
|
||||||
|
} catch (classNotFound: ClassNotFoundException) {
|
||||||
|
val javaHome = System.getProperty("java.home") // current Java installation path
|
||||||
|
throw GradleException(
|
||||||
|
"Kotlin could not find the required JDK tools in the Java installation ${javaHome?.let { "'$it' " }.orEmpty()}" +
|
||||||
|
"used by Gradle. Make sure Gradle is running on a JDK, not JRE.",
|
||||||
|
classNotFound
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return javacUtilContextClass?.let(::findJarByClass)
|
||||||
|
}
|
||||||
|
|
||||||
internal fun findCoroutinesClasspath(): List<File> {
|
internal fun findCoroutinesClasspath(): List<File> {
|
||||||
val classLoader = Thread.currentThread().contextClassLoader
|
val classLoader = Thread.currentThread().contextClassLoader
|
||||||
|
|||||||
Reference in New Issue
Block a user