From ff687131b16034ee528700b9ea71e7235dc83347 Mon Sep 17 00:00:00 2001 From: Sergey Igushkin Date: Wed, 4 Oct 2017 20:24:42 +0300 Subject: [PATCH] Rename `implement` to `expectedBy` in Gradle, deprecate the old name Issue #KT-20618 Fixed (cherry picked from commit 6e0d378) --- .../kotlin/gradle/KotlinGradlePluginIT.kt | 21 ++++++++++++ .../multiplatformProject/libJs/build.gradle | 2 +- .../multiplatformProject/libJvm/build.gradle | 2 +- .../plugin/KotlinMultiplatformPlugin.kt | 34 ++++++++++++++----- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt index 7b1a8d5f7fb..b8aa1cb9af4 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt @@ -20,6 +20,7 @@ import org.gradle.api.logging.LogLevel import com.intellij.openapi.util.io.FileUtil import org.jetbrains.kotlin.gradle.plugin.CopyClassesToJavaOutputStatus import org.jetbrains.kotlin.gradle.tasks.USING_INCREMENTAL_COMPILATION_MESSAGE +import org.jetbrains.kotlin.gradle.plugin.IMPLEMENT_CONFIG_WARNING import org.jetbrains.kotlin.gradle.util.* import org.junit.Test import java.io.File @@ -406,6 +407,26 @@ class KotlinGradleIT: BaseGradleIT() { } } + @Test + fun testDeprecatedImplementWarning() { + val project = Project("multiplatformProject", GRADLE_VERSION) + val warningText = IMPLEMENT_CONFIG_WARNING + + project.build("build") { + assertSuccessful() + assertNotContains(warningText) + } + + project.projectDir.walk().filter { it.name == "build.gradle" }.forEach { buildGradle -> + buildGradle.modify { it.replace("expectedBy", "implement") } + } + + project.build("build") { + assertSuccessful() + assertContains(warningText) + } + } + @Test fun testFreeCompilerArgs() { val project = Project("kotlinProject", GRADLE_VERSION) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/multiplatformProject/libJs/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/multiplatformProject/libJs/build.gradle index 39d39f6489e..9ec7941685f 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/multiplatformProject/libJs/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/multiplatformProject/libJs/build.gradle @@ -1,5 +1,5 @@ apply plugin: 'kotlin-platform-js' dependencies { - implement project(":lib") + expectedBy project(":lib") } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/multiplatformProject/libJvm/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/multiplatformProject/libJvm/build.gradle index 55e087896da..c5f014ee3fc 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/multiplatformProject/libJvm/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/multiplatformProject/libJvm/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'kotlin-platform-jvm' dependencies { - implement project(":lib") + expectedBy project(":lib") compile 'com.google.guava:guava:20.0' } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinMultiplatformPlugin.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinMultiplatformPlugin.kt index dbdb2960ec9..32fdd8ea7f4 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinMultiplatformPlugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinMultiplatformPlugin.kt @@ -35,6 +35,8 @@ open class KotlinPlatformCommonPlugin : KotlinPlatformPluginBase("common") { } } +const val IMPLEMENT_CONFIG_WARNING = "The 'implement' configuration is deprecated and will be removed. Use 'expectedBy' instead." + open class KotlinPlatformImplementationPluginBase(platformName: String) : KotlinPlatformPluginBase(platformName) { private val commonProjects = arrayListOf() private val platformKotlinTasksBySourceSetName = hashMapOf>() @@ -47,13 +49,29 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin project.tasks.filterIsInstance>().associateByTo(platformKotlinTasksBySourceSetName) { it.sourceSetName } val implementConfig = project.configurations.create("implement") - implementConfig.isTransitive = false - implementConfig.dependencies.whenObjectAdded { dep -> - if (dep is ProjectDependency) { - addCommonProject(dep.dependencyProject, project) + val expectedByConfig = project.configurations.create("expectedBy").apply { + extendsFrom(implementConfig) + } + + listOf(implementConfig, expectedByConfig).forEach { config -> + config.isTransitive = false + + config.dependencies.whenObjectAdded { dep -> + if (dep is ProjectDependency) { + addCommonProject(dep.dependencyProject, project) + } + else { + throw GradleException("$project '${config.name}' dependency is not a project: $dep") + } } - else { - throw GradleException("$project `implement` dependency is not a project: $dep") + } + + var implementDeprecationWarningShown = false + + implementConfig.dependencies.whenObjectAdded { + if (!implementDeprecationWarningShown) { + implementDeprecationWarningShown = true + project.logger.kotlinWarn(IMPLEMENT_CONFIG_WARNING) } } } @@ -61,12 +79,12 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin private fun addCommonProject(commonProject: Project, platformProject: Project) { commonProjects.add(commonProject) if (commonProjects.size > 1) { - throw GradleException("Platform project $platformProject implements more than one common project: ${commonProjects.joinToString()}") + throw GradleException("Platform project $platformProject is expected by more than one common project: ${commonProjects.joinToString()}") } commonProject.whenEvaluated { if ((!commonProject.plugins.hasPlugin(KotlinPlatformCommonPlugin::class.java))) { - throw GradleException("Platform project $platformProject implements non-common project $commonProject (`apply plugin 'kotlin-platform-kotlin'`)") + throw GradleException("Platform project $platformProject is expected by non-common project $commonProject (`apply plugin 'kotlin-platform-kotlin'`)") } commonProject.sourceSets.all { commonSourceSet ->