From af8b0ffa6dd77f885d6677153805c2087fddd212 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Wed, 30 May 2018 01:45:08 +0300 Subject: [PATCH] Resolve compiler classpath using 'kotlinCompilerClasspath' configuration #KT-24675 fixed --- .../testProject/duplicatedClass/build.gradle | 7 ++++++ .../incrementalMultiproject/build.gradle | 4 ++-- .../kotlinProjectWithBuildSrc/build.gradle | 7 +++++- .../testProject/languageVersion/build.gradle | 7 +++++- .../moveClassToOtherModule/build.gradle | 9 ++++++- .../kotlin/gradle/plugin/KotlinPlugin.kt | 4 ++++ .../jetbrains/kotlin/gradle/tasks/Tasks.kt | 24 ++++++++++++++++--- .../kotlin/gradle/tasks/jarSearchingUtil.kt | 4 ++-- prepare/compiler-embeddable/build.gradle.kts | 2 +- 9 files changed, 57 insertions(+), 11 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/duplicatedClass/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/duplicatedClass/build.gradle index b1b941981c6..f37b00da1c9 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/duplicatedClass/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/duplicatedClass/build.gradle @@ -6,4 +6,11 @@ buildscript { dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } +} + +subprojects { + repositories { + mavenLocal() + mavenCentral() + } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/incrementalMultiproject/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/incrementalMultiproject/build.gradle index b92f0b49f06..f37b00da1c9 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/incrementalMultiproject/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/incrementalMultiproject/build.gradle @@ -8,9 +8,9 @@ buildscript { } } -allprojects { - // for test with groovy +subprojects { repositories { + mavenLocal() mavenCentral() } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlinProjectWithBuildSrc/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlinProjectWithBuildSrc/build.gradle index 770686d110a..1d83b293943 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlinProjectWithBuildSrc/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlinProjectWithBuildSrc/build.gradle @@ -1 +1,6 @@ -apply plugin: 'kotlin' \ No newline at end of file +apply plugin: 'kotlin' + +repositories { + mavenLocal() + mavenCentral() +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/languageVersion/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/languageVersion/build.gradle index 6b3dc458b89..1b2ea2be34a 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/languageVersion/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/languageVersion/build.gradle @@ -1,7 +1,7 @@ buildscript { repositories { mavenLocal() - jcenter() + mavenCentral() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" @@ -10,6 +10,11 @@ buildscript { apply plugin: "kotlin" +repositories { + mavenLocal() + mavenCentral() +} + compileKotlin { kotlinOptions { languageVersion = "1.0" diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/moveClassToOtherModule/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/moveClassToOtherModule/build.gradle index 5d567556933..f37b00da1c9 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/moveClassToOtherModule/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/moveClassToOtherModule/build.gradle @@ -1,9 +1,16 @@ buildscript { repositories { mavenLocal() - jcenter() + mavenCentral() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } +} + +subprojects { + repositories { + mavenLocal() + mavenCentral() + } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt index 68fa1770e91..753f6881449 100755 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt @@ -37,6 +37,7 @@ import java.util.concurrent.Callable import java.util.jar.Manifest internal const val PLUGIN_CLASSPATH_CONFIGURATION_NAME = "kotlinCompilerPluginClasspath" +internal const val COMPILER_CLASSPATH_CONFIGURATION_NAME = "kotlinCompilerClasspath" val KOTLIN_DSL_NAME = "kotlin" val KOTLIN_JS_DSL_NAME = "kotlin2js" val KOTLIN_OPTIONS_DSL_NAME = "kotlinOptions" @@ -337,6 +338,9 @@ internal abstract class AbstractKotlinPlugin( internal abstract fun buildSourceSetProcessor(project: Project, javaBasePlugin: JavaBasePlugin, sourceSet: SourceSet, kotlinPluginVersion: String): KotlinSourceSetProcessor<*> override fun apply(project: Project) { + project.configurations.create(COMPILER_CLASSPATH_CONFIGURATION_NAME).defaultDependencies { + it.add(project.dependencies.create("$KOTLIN_MODULE_GROUP:$KOTLIN_COMPILER_EMBEDDABLE:$kotlinPluginVersion")) + } project.configurations.create(PLUGIN_CLASSPATH_CONFIGURATION_NAME).apply { // todo: Consider removing if org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser stops using parent last classloader isTransitive = false diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index f3ccfd5444a..09d36d0710e 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -42,12 +42,31 @@ const val USING_INCREMENTAL_COMPILATION_MESSAGE = "Using Kotlin incremental comp const val USING_EXPERIMENTAL_JS_INCREMENTAL_COMPILATION_MESSAGE = "Using experimental Kotlin/JS incremental compilation" abstract class AbstractKotlinCompileTool() : AbstractCompile(), CompilerArgumentAwareWithInput { - // TODO: deprecate and remove + private fun useCompilerClasspathConfigurationMessage(propertyName: String) { + project.logger.kotlinWarn( + "'$path.$propertyName' is deprecated and will be removed soon. " + + "Use '$COMPILER_CLASSPATH_CONFIGURATION_NAME' " + + "configuration for customizing compiler classpath." + ) + } + + // TODO: remove @get:Internal var compilerJarFile: File? = null + @Deprecated("Use $COMPILER_CLASSPATH_CONFIGURATION_NAME configuration") + set(value) { + useCompilerClasspathConfigurationMessage("compilerJarFile") + field = value + } + // TODO: remove @get:Internal var compilerClasspath: List? = null + @Deprecated("Use $COMPILER_CLASSPATH_CONFIGURATION_NAME configuration") + set(value) { + useCompilerClasspathConfigurationMessage("compilerClasspath") + field = value + } @InputFiles @PathSensitive(PathSensitivity.RELATIVE) @@ -60,8 +79,7 @@ abstract class AbstractKotlinCompileTool() : AbstractCo // a hack to remove compiler jar from the cp, will be dropped when compilerJarFile will be removed listOf(it) + findKotlinCompilerClasspath(project).filter { !it.name.startsWith("kotlin-compiler") } } - ?: findKotlinCompilerClasspath(project).takeIf { it.isNotEmpty() } - ?: throw IllegalStateException("Could not find Kotlin Compiler classpath. Please specify $name.compilerClasspath") + ?: project.configurations.getByName(COMPILER_CLASSPATH_CONFIGURATION_NAME).resolve().toList() protected abstract fun findKotlinCompilerClasspath(project: Project): List } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/jarSearchingUtil.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/jarSearchingUtil.kt index ddbc7ae6ee9..1c3175bf9e5 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/jarSearchingUtil.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/jarSearchingUtil.kt @@ -38,9 +38,9 @@ private val KOTLIN_SCRIPT_RUNTIME_EXPECTED_CLASS = "kotlin.script.templates.Anno private val KOTLIN_SCRIPT_ANNOTATION_EXPECTED_CLASS = "kotlin.script.experimental.annotations.KotlinScript" private val KOTLIN_JVM_SCRIPT_COMPILER_EXPECTED_CLASS = "kotlin.script.experimental.jvm.JvmScriptCompiler" private val KOTLIN_REFLECT_EXPECTED_CLASS = "kotlin.reflect.full.KClasses" -private val KOTLIN_MODULE_GROUP = "org.jetbrains.kotlin" +internal const val KOTLIN_MODULE_GROUP = "org.jetbrains.kotlin" private val KOTLIN_GRADLE_PLUGIN = "kotlin-gradle-plugin" -private val KOTLIN_COMPILER_EMBEDDABLE = "kotlin-compiler-embeddable" +internal const val KOTLIN_COMPILER_EMBEDDABLE = "kotlin-compiler-embeddable" private val KOTLIN_STDLIB = "kotlin-stdlib" private val KOTLIN_SCRIPT_RUNTIME = "kotlin-script-runtime" private val KOTLIN_SCRIPT_COMMON = "kotlin-scripting-common" diff --git a/prepare/compiler-embeddable/build.gradle.kts b/prepare/compiler-embeddable/build.gradle.kts index 16c23fb19e0..29f312ea5d6 100644 --- a/prepare/compiler-embeddable/build.gradle.kts +++ b/prepare/compiler-embeddable/build.gradle.kts @@ -8,7 +8,7 @@ plugins { dependencies { runtime(project(":kotlin-stdlib")) runtime(project(":kotlin-script-runtime")) - runtimeOnly(project(":kotlin-reflect")) + runtime(project(":kotlin-reflect")) } noDefaultJar()