Fix runtime elements configuration resolved for compile classpath

The existing disambiguation rule for the Usage attribute lead to
runtime variants being resolved even for compile-scoped input
configurations, because Gradle runs disambiguation rules even if the
consumer value is present in the candidates list.

For example, an `app` project's `jvmCompileClasspath` configuration
would get its `project('lib')` dependency resolved to the
`jvmLibRuntimeElements` instead of `jvmLibApiElements`.

Fix this by:
1) running the part of the disambiguation rule only with Gradle 4.1+, so
  as to use the consumer value for proper disambiguation;
2) choosing the JAVA_API usage when the consumer is JAVA_API or
  KOTLIN_API, and choosing one of the JAVA_RUNTIME usages if the
  consumer is either KOTLIN_RUNTIME, one of the JAVA_RUNTIME usages, or
  does not specify its usage.

Issue #KT-27849 Fixed
This commit is contained in:
Sergey Igushkin
2018-10-29 16:28:00 +03:00
parent 43e79035e9
commit f995afd50d
2 changed files with 45 additions and 7 deletions
@@ -241,6 +241,30 @@ class VariantAwareDependenciesIT : BaseGradleIT() {
}
}
@Test
fun testCompileAndRuntimeResolutionOfElementsConfigurations() =
with(Project("sample-app", gradleVersion, "new-mpp-lib-and-app")) {
val libProject = Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")
embedProject(libProject)
gradleBuildScript().modify {
it.replace("'com.example:sample-lib:1.0'", "project('${libProject.projectName}')")
}
listOf("jvm6" to "Classpath", "nodeJs" to "Classpath", "wasm32" to "Klibraries").forEach { (target, suffix) ->
build("dependencyInsight", "--configuration", "${target}Compile$suffix", "--dependency", "sample-lib") {
assertSuccessful()
assertContains("variant \"${target}ApiElements\" [")
}
if (suffix == "Classpath") {
build("dependencyInsight", "--configuration", "${target}Runtime$suffix", "--dependency", "sample-lib") {
assertSuccessful()
assertContains("variant \"${target}RuntimeElements\" [")
}
}
}
}
private fun Project.embedProject(other: Project) {
setupWorkingDir()
other.setupWorkingDir()