Fix resolution of Java Usage artifacts for configurations with no usage
When Gradle resolves a dependency on a publication with no metadata (or with metadata disabled), it represents it as two variants, one with Usage `java-api`, the other with `java-runtime`. It turns out that the `java-api` one does not contain transitive dependencies with Maven scope `runtime`. This commit makes the Kotlin Gradle plugin disambiguation rules behave the same way as those defined in the JavaBasePlugin: when no Usage is requested, prefer the runtime usages as they are more complete.
This commit is contained in:
+17
@@ -224,6 +224,23 @@ class VariantAwareDependenciesIT : BaseGradleIT() {
|
||||
testResolveAllConfigurations("sample-lib")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConfigurationsWithNoExplicitUsageResolveRuntime() =
|
||||
// Starting with Gradle 5.0, plain Maven dependencies are represented as two variants, and resolving them to the API one leads
|
||||
// to transitive dependencies left out of the resolution results. We need to ensure that our attributes schema does not lead to the API
|
||||
// variants chosen over the runtime ones when resolving a configuration with no required Usage:
|
||||
with(Project("simpleProject", GradleVersionRequired.AtLeast("5.0-milestone-1"))) {
|
||||
setupWorkingDir()
|
||||
gradleBuildScript().appendText("\ndependencies { compile 'org.jetbrains.kotlin:kotlin-compiler-embeddable' }")
|
||||
|
||||
testResolveAllConfigurations {
|
||||
assertContains(">> :compile --> kotlin-compiler-embeddable-${defaultBuildOptions().kotlinVersion}.jar")
|
||||
|
||||
// Check that the transitive dependencies with 'runtime' scope are also available:
|
||||
assertContains(">> :compile --> kotlin-script-runtime-${defaultBuildOptions().kotlinVersion}.jar")
|
||||
}
|
||||
}
|
||||
|
||||
private fun Project.embedProject(other: Project) {
|
||||
setupWorkingDir()
|
||||
other.setupWorkingDir()
|
||||
|
||||
+2
-2
@@ -71,10 +71,10 @@ object KotlinUsages {
|
||||
details.closestMatch(candidateValues.single { it?.name == KOTLIN_RUNTIME }!!)
|
||||
}
|
||||
if (JAVA_API in candidateNames && JAVA_RUNTIME_JARS in candidateNames && values.none { it in candidateNames }) {
|
||||
details.closestMatch(candidateValues.single { it?.name == JAVA_API }!!)
|
||||
details.closestMatch(candidateValues.single { it?.name == JAVA_RUNTIME_JARS }!!)
|
||||
}
|
||||
if (JAVA_API in candidateNames && JAVA_RUNTIME in candidateNames && values.none { it in candidateNames }) {
|
||||
details.closestMatch(candidateValues.single { it?.name == JAVA_API }!!)
|
||||
details.closestMatch(candidateValues.single { it?.name == JAVA_RUNTIME }!!)
|
||||
}
|
||||
if (JAVA_RUNTIME_CLASSES in candidateNames && JAVA_RUNTIME_RESOURCES in candidateNames && KOTLIN_RUNTIME in candidateNames) {
|
||||
closestMatch(candidateValues.single { it?.name == KOTLIN_RUNTIME }!!)
|
||||
|
||||
Reference in New Issue
Block a user