Changes related to the 'expectedBy' Gradle configuration:
* Remove the `extendsFrom` relation; * Refactor, reword warnings; * Add the new expectedBy name to `KotlinGradleModelBuilder.kt`. (cherry picked from commit de198f0)
This commit is contained in:
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.gradle
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.artifacts.ProjectDependency
|
||||
import org.gradle.tooling.ModelBuilder
|
||||
import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder
|
||||
import org.jetbrains.plugins.gradle.tooling.ModelBuilderService
|
||||
import java.io.File
|
||||
@@ -92,7 +91,7 @@ class KotlinGradleModelBuilder : AbstractKotlinGradleModelBuilder() {
|
||||
override fun canBuild(modelName: String?): Boolean = modelName == KotlinGradleModel::class.java.name
|
||||
|
||||
private fun getImplements(project: Project): Project? {
|
||||
val implementsConfiguration = project.configurations.findByName("implement") ?: return null
|
||||
val implementsConfiguration = project.configurations.run { findByName("expectedBy") ?: findByName("implement") } ?: return null
|
||||
val implementsProjectDependency = implementsConfiguration.dependencies.filterIsInstance<ProjectDependency>().firstOrNull()
|
||||
return implementsProjectDependency?.dependencyProject
|
||||
}
|
||||
|
||||
+4
-5
@@ -20,7 +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.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.util.*
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
@@ -410,20 +410,19 @@ class KotlinGradleIT: BaseGradleIT() {
|
||||
@Test
|
||||
fun testDeprecatedImplementWarning() {
|
||||
val project = Project("multiplatformProject", GRADLE_VERSION)
|
||||
val warningText = IMPLEMENT_CONFIG_WARNING
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
assertNotContains(warningText)
|
||||
assertNotContains(IMPLEMENT_DEPRECATION_WARNING)
|
||||
}
|
||||
|
||||
project.projectDir.walk().filter { it.name == "build.gradle" }.forEach { buildGradle ->
|
||||
buildGradle.modify { it.replace("expectedBy", "implement") }
|
||||
buildGradle.modify { it.replace(EXPECTED_BY_CONFIG_NAME, IMPLEMENT_CONFIG_NAME) }
|
||||
}
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
assertContains(warningText)
|
||||
assertContains(IMPLEMENT_DEPRECATION_WARNING)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-15
@@ -35,7 +35,11 @@ open class KotlinPlatformCommonPlugin : KotlinPlatformPluginBase("common") {
|
||||
}
|
||||
}
|
||||
|
||||
const val IMPLEMENT_CONFIG_WARNING = "The 'implement' configuration is deprecated and will be removed. Use 'expectedBy' instead."
|
||||
const val EXPECTED_BY_CONFIG_NAME = "expectedBy"
|
||||
|
||||
const val IMPLEMENT_CONFIG_NAME = "implement"
|
||||
const val IMPLEMENT_DEPRECATION_WARNING = "The '$IMPLEMENT_CONFIG_NAME' configuration is deprecated and will be removed. " +
|
||||
"Use '$EXPECTED_BY_CONFIG_NAME' instead."
|
||||
|
||||
open class KotlinPlatformImplementationPluginBase(platformName: String) : KotlinPlatformPluginBase(platformName) {
|
||||
private val commonProjects = arrayListOf<Project>()
|
||||
@@ -48,9 +52,14 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
|
||||
|
||||
project.tasks.filterIsInstance<AbstractKotlinCompile<*>>().associateByTo(platformKotlinTasksBySourceSetName) { it.sourceSetName }
|
||||
|
||||
val implementConfig = project.configurations.create("implement")
|
||||
val expectedByConfig = project.configurations.create("expectedBy").apply {
|
||||
extendsFrom(implementConfig)
|
||||
val implementConfig = project.configurations.create(IMPLEMENT_CONFIG_NAME)
|
||||
val expectedByConfig = project.configurations.create(EXPECTED_BY_CONFIG_NAME)
|
||||
|
||||
implementConfig.dependencies.whenObjectAdded {
|
||||
if (!implementConfigurationIsUsed) {
|
||||
implementConfigurationIsUsed = true
|
||||
project.logger.kotlinWarn(IMPLEMENT_DEPRECATION_WARNING)
|
||||
}
|
||||
}
|
||||
|
||||
listOf(implementConfig, expectedByConfig).forEach { config ->
|
||||
@@ -65,26 +74,25 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var implementDeprecationWarningShown = false
|
||||
|
||||
implementConfig.dependencies.whenObjectAdded {
|
||||
if (!implementDeprecationWarningShown) {
|
||||
implementDeprecationWarningShown = true
|
||||
project.logger.kotlinWarn(IMPLEMENT_CONFIG_WARNING)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var implementConfigurationIsUsed = false
|
||||
|
||||
private fun addCommonProject(commonProject: Project, platformProject: Project) {
|
||||
commonProjects.add(commonProject)
|
||||
if (commonProjects.size > 1) {
|
||||
throw GradleException("Platform project $platformProject is expected by more than one common project: ${commonProjects.joinToString()}")
|
||||
throw GradleException(
|
||||
"Platform project $platformProject has more than one " +
|
||||
"'$EXPECTED_BY_CONFIG_NAME'${if (implementConfigurationIsUsed) "/'$IMPLEMENT_CONFIG_NAME'" else ""} " +
|
||||
"dependency: ${commonProjects.joinToString()}")
|
||||
}
|
||||
|
||||
commonProject.whenEvaluated {
|
||||
if ((!commonProject.plugins.hasPlugin(KotlinPlatformCommonPlugin::class.java))) {
|
||||
throw GradleException("Platform project $platformProject is expected by non-common project $commonProject (`apply plugin 'kotlin-platform-kotlin'`)")
|
||||
throw GradleException(
|
||||
"Platform project $platformProject has an " +
|
||||
"'$EXPECTED_BY_CONFIG_NAME'${if (implementConfigurationIsUsed) "/'$IMPLEMENT_CONFIG_NAME'" else ""} " +
|
||||
"dependency to non-common project $commonProject")
|
||||
}
|
||||
|
||||
commonProject.sourceSets.all { commonSourceSet ->
|
||||
|
||||
Reference in New Issue
Block a user