提交 2a46648e 编写于 作者: S Sergey Igushkin

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
上级 37d7c36b
......@@ -289,10 +289,21 @@ fun getSomething() = 10
}
@Test
fun testMultiplatformAndroidCompile() {
val project = Project("multiplatformAndroidProject", gradleVersion)
fun testMultiplatformAndroidCompile() = with(Project("multiplatformAndroidProject", gradleVersion)) {
setupWorkingDir()
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()
)
}
project.build("build") {
build("build") {
assertSuccessful()
assertTasksExecuted(
":lib:compileKotlinCommon",
......
......@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.gradle.plugin
import com.android.build.gradle.BaseExtension
import org.gradle.api.*
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.file.SourceDirectorySet
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) {
private val commonProjects = arrayListOf<Project>()
protected open fun configurationsForCommonModuleDependency(project: Project): List<Configuration> =
listOf(project.configurations.getByName("compile"))
override fun apply(project: Project) {
val implementConfig = project.configurations.create(IMPLEMENT_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
// 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 {
throw GradleException("$project '${config.name}' dependency is not a project: $dep")
......@@ -177,6 +183,10 @@ open class KotlinPlatformAndroidPlugin : KotlinPlatformImplementationPluginBase(
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<*> =
(project.extensions.getByName("android") as BaseExtension).sourceSets
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册