Mark deprecated Gradle configurations with the Kotlin platform attribute
The traditional Gradle/Java model assumes several configurations, which are now deprecated, which are both `canBeConsumed = true` and `canBeResolved = true`. * compile, testCompile, etc. * runtime, testRuntime, etc. * default These configurations need to somehow resolve correctly to an appropriate platform-specific artifact when they contain an MPP library or project dependency. However, simply marking them with the Kotlin platform type attribute would put these configurations under considerations during Gradle variant aware depdendency resolution of project dependencies, which in order would lead to ambiguity (e.g. `compile` vs `runtime` vs `testCompile` vs ... vs `apiElements`). To deprioritize these configurations during dependency resolution, we mark them with a special attribute with a unique value in each project. Given that the values are different in different projects, Gradle will not choose a configuration marked by this attribute. But we still need 'project(path: '...', configuration: '...')` dependencies to work, and so, instead of rejecting those different values of the attribute, we say that all values are compatible, but when an ambiguity arises, choose the configurations not marked by this attribute, so effectively eliminating them from resolution. Issue #KT-27111 Fixed
This commit is contained in:
+76
-2
@@ -21,7 +21,9 @@ class VariantAwareDependenciesIT : BaseGradleIT() {
|
||||
embedProject(innerProject)
|
||||
gradleBuildScript(innerProject.projectName).appendText("\ndependencies { compile rootProject }")
|
||||
|
||||
testResolveAllConfigurations(innerProject.projectName)
|
||||
testResolveAllConfigurations(innerProject.projectName) {
|
||||
assertContains(">> :${innerProject.projectName}:runtime --> sample-lib-jvm6-1.0.jar")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +36,9 @@ class VariantAwareDependenciesIT : BaseGradleIT() {
|
||||
embedProject(innerProject)
|
||||
gradleBuildScript(innerProject.projectName).appendText("\nrepositories { jcenter() }; dependencies { compile rootProject }")
|
||||
|
||||
testResolveAllConfigurations(innerProject.projectName)
|
||||
testResolveAllConfigurations(innerProject.projectName) {
|
||||
assertContains(">> :${innerProject.projectName}:runtime --> sample-lib-nodejs-1.0.jar")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +110,76 @@ class VariantAwareDependenciesIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMppResolvesJvmAndJsKtLibs() {
|
||||
val outerProject = Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")
|
||||
val innerJvmProject = Project("simpleProject")
|
||||
val innerJsProject = Project("kotlin2JsInternalTest")
|
||||
|
||||
with(outerProject) {
|
||||
embedProject(innerJvmProject)
|
||||
embedProject(innerJsProject)
|
||||
|
||||
gradleBuildScript().appendText("\n" + """
|
||||
dependencies {
|
||||
jvm6Implementation project(':${innerJvmProject.projectName}')
|
||||
jvm6TestRuntime project(':${innerJvmProject.projectName}')
|
||||
nodeJsImplementation project(':${innerJsProject.projectName}')
|
||||
nodeJsTestRuntime project(':${innerJsProject.projectName}')
|
||||
}
|
||||
""".trimIndent())
|
||||
|
||||
testResolveAllConfigurations(innerJvmProject.projectName)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testJvmKtAppDependsOnMppTestRuntime() {
|
||||
val outerProject = Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")
|
||||
val innerProject = Project("simpleProject")
|
||||
|
||||
with(outerProject) {
|
||||
embedProject(innerProject)
|
||||
|
||||
gradleBuildScript(innerProject.projectName).appendText(
|
||||
"\ndependencies { testCompile project(path: ':', configuration: 'jvm6TestRuntime') }"
|
||||
)
|
||||
|
||||
testResolveAllConfigurations(innerProject.projectName) {
|
||||
assertContains(">> :${innerProject.projectName}:testCompile --> sample-lib-jvm6-1.0.jar")
|
||||
assertContains(">> :${innerProject.projectName}:testRuntime --> sample-lib-jvm6-1.0.jar")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testKtAppResolvesOldMpp() {
|
||||
val outerProject = Project("multiplatformProject")
|
||||
val innerJvmProject = Project("simpleProject")
|
||||
val innerJsProject = Project("kotlin2JsInternalTest")
|
||||
|
||||
with(outerProject) {
|
||||
embedProject(innerJvmProject)
|
||||
embedProject(innerJsProject)
|
||||
|
||||
listOf(innerJvmProject to ":libJvm", innerJsProject to ":libJs").forEach { (project, dependency) ->
|
||||
gradleBuildScript(project.projectName).appendText(
|
||||
"\n" + """
|
||||
configurations.create('foo')
|
||||
dependencies {
|
||||
foo project('$dependency')
|
||||
compile project('$dependency')
|
||||
foo project(':lib')
|
||||
compile project(':lib')
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
testResolveAllConfigurations(project.projectName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Project.embedProject(other: Project) {
|
||||
setupWorkingDir()
|
||||
other.setupWorkingDir()
|
||||
|
||||
Reference in New Issue
Block a user