In Android MPP target, add common module dependency to api configuration
Since Android considers the `compile` configuration as deprecated and reports a warning when a dependency is added to it, use the `api` configuration when dealing with an Android platform module. Issue #KT-23719 Fixed
This commit is contained in:
+14
-3
@@ -289,10 +289,21 @@ fun getSomething() = 10
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testMultiplatformAndroidCompile() {
|
fun testMultiplatformAndroidCompile() = with(Project("multiplatformAndroidProject", gradleVersion)) {
|
||||||
val project = Project("multiplatformAndroidProject", gradleVersion)
|
setupWorkingDir()
|
||||||
|
|
||||||
project.build("build") {
|
if (!isLegacyAndroidGradleVersion(androidGradlePluginVersion)) {
|
||||||
|
// Check that the common module is not added to the deprecated configuration 'compile' (KT-23719):
|
||||||
|
gradleBuildScript("libAndroid").appendText(
|
||||||
|
"""${'\n'}
|
||||||
|
configurations.compile.dependencies.all { aDependencyExists ->
|
||||||
|
throw GradleException("Check failed")
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
build("build") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTasksExecuted(
|
assertTasksExecuted(
|
||||||
":lib:compileKotlinCommon",
|
":lib:compileKotlinCommon",
|
||||||
|
|||||||
+11
-1
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.gradle.plugin
|
|||||||
|
|
||||||
import com.android.build.gradle.BaseExtension
|
import com.android.build.gradle.BaseExtension
|
||||||
import org.gradle.api.*
|
import org.gradle.api.*
|
||||||
|
import org.gradle.api.artifacts.Configuration
|
||||||
import org.gradle.api.artifacts.ProjectDependency
|
import org.gradle.api.artifacts.ProjectDependency
|
||||||
import org.gradle.api.file.SourceDirectorySet
|
import org.gradle.api.file.SourceDirectorySet
|
||||||
import org.gradle.api.plugins.JavaPluginConvention
|
import org.gradle.api.plugins.JavaPluginConvention
|
||||||
@@ -49,6 +50,9 @@ const val IMPLEMENT_DEPRECATION_WARNING = "The '$IMPLEMENT_CONFIG_NAME' configur
|
|||||||
open class KotlinPlatformImplementationPluginBase(platformName: String) : KotlinPlatformPluginBase(platformName) {
|
open class KotlinPlatformImplementationPluginBase(platformName: String) : KotlinPlatformPluginBase(platformName) {
|
||||||
private val commonProjects = arrayListOf<Project>()
|
private val commonProjects = arrayListOf<Project>()
|
||||||
|
|
||||||
|
protected open fun configurationsForCommonModuleDependency(project: Project): List<Configuration> =
|
||||||
|
listOf(project.configurations.getByName("compile"))
|
||||||
|
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
val implementConfig = project.configurations.create(IMPLEMENT_CONFIG_NAME)
|
val implementConfig = project.configurations.create(IMPLEMENT_CONFIG_NAME)
|
||||||
val expectedByConfig = project.configurations.create(EXPECTED_BY_CONFIG_NAME)
|
val expectedByConfig = project.configurations.create(EXPECTED_BY_CONFIG_NAME)
|
||||||
@@ -69,7 +73,9 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
|
|||||||
|
|
||||||
// Needed for the projects that depend on this one to recover the common module sources through
|
// Needed for the projects that depend on this one to recover the common module sources through
|
||||||
// the transitive dependency (also, it will be added to the POM generated by Gradle):
|
// the transitive dependency (also, it will be added to the POM generated by Gradle):
|
||||||
project.configurations.getByName("compile").dependencies.add(dep)
|
configurationsForCommonModuleDependency(project).forEach { configuration ->
|
||||||
|
configuration.dependencies.add(dep)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw GradleException("$project '${config.name}' dependency is not a project: $dep")
|
throw GradleException("$project '${config.name}' dependency is not a project: $dep")
|
||||||
@@ -177,6 +183,10 @@ open class KotlinPlatformAndroidPlugin : KotlinPlatformImplementationPluginBase(
|
|||||||
super.apply(project)
|
super.apply(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun configurationsForCommonModuleDependency(project: Project): List<Configuration> =
|
||||||
|
(project.configurations.findByName("api"))?.let(::listOf)
|
||||||
|
?: super.configurationsForCommonModuleDependency(project) // older Android plugins don't have api/implementation configs
|
||||||
|
|
||||||
override fun namedSourceSetsContainer(project: Project): NamedDomainObjectContainer<*> =
|
override fun namedSourceSetsContainer(project: Project): NamedDomainObjectContainer<*> =
|
||||||
(project.extensions.getByName("android") as BaseExtension).sourceSets
|
(project.extensions.getByName("android") as BaseExtension).sourceSets
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user