Fix unresolved library with 'java-api' and 'java-runtime' usages

This commit is contained in:
Sergey Igushkin
2018-09-29 13:32:02 +03:00
parent d77a0f109b
commit 748dc203e5
2 changed files with 49 additions and 1 deletions
@@ -180,6 +180,50 @@ class VariantAwareDependenciesIT : BaseGradleIT() {
}
}
@Test
fun testResolvesOldKotlinArtifactsPublishedWithMetadata() = with(Project("multiplatformProject", gradleVersion)) {
setupWorkingDir()
projectDir.resolve("settings.gradle").appendText("\nenableFeaturePreview 'GRADLE_METADATA'")
gradleBuildScript().appendText(
"\n" + """
configure([project(':lib'), project(':libJvm'), project(':libJs')]) {
group 'com.example.oldmpp'
version '1.0'
apply plugin: 'maven-publish'
publishing {
repositories { maven { url "file://${'$'}{rootDir.absolutePath.replace('\\', '/')}/repo" } }
publications { kotlin(MavenPublication) { from(components.java) } }
}
}
""".trimIndent()
)
build("publish") { assertSuccessful() }
gradleBuildScript().modify {
it.replace("'com.example.oldmpp'", "'com.example.consumer'") +
"\nsubprojects { repositories { maven { url \"file://${'$'}{rootDir.absolutePath.replace('\\\\', '/')}/repo\" } } }"
}
gradleBuildScript("lib").appendText("\ndependencies { compile 'com.example.oldmpp:lib:1.0' }")
testResolveAllConfigurations("lib")
gradleBuildScript("libJvm").appendText("\ndependencies { compile 'com.example.oldmpp:libJvm:1.0' }")
testResolveAllConfigurations("libJvm")
gradleBuildScript("libJs").appendText("\ndependencies { compile 'com.example.oldmpp:libJs:1.0' }")
testResolveAllConfigurations("libJs")
embedProject(Project("sample-lib", directoryPrefix = "new-mpp-lib-and-app"))
gradleBuildScript("sample-lib").appendText("\n" + """
dependencies {
commonMainApi 'com.example.oldmpp:lib:1.0'
jvm6MainApi 'com.example.oldmpp:libJvm:1.0'
nodeJsMainApi 'com.example.oldmpp:libJs:1.0'
}
""".trimIndent())
testResolveAllConfigurations("sample-lib")
}
private fun Project.embedProject(other: Project) {
setupWorkingDir()
other.setupWorkingDir()
@@ -55,7 +55,8 @@ object KotlinUsages {
override fun execute(details: CompatibilityCheckDetails<Usage>) = with(details) {
when {
consumerValue?.name == KOTLIN_API && producerValue?.name == JAVA_API -> compatible()
consumerValue?.name in values && producerValue?.name == JAVA_RUNTIME_JARS -> compatible()
consumerValue?.name in values &&
producerValue?.name.let { it == JAVA_RUNTIME || it == JAVA_RUNTIME_JARS } -> compatible()
}
}
}
@@ -72,6 +73,9 @@ object KotlinUsages {
if (JAVA_API in candidateNames && JAVA_RUNTIME_JARS in candidateNames && values.none { it in candidateNames }) {
details.closestMatch(candidateValues.single { it?.name == JAVA_API }!!)
}
if (JAVA_API in candidateNames && JAVA_RUNTIME in candidateNames && values.none { it in candidateNames }) {
details.closestMatch(candidateValues.single { it?.name == JAVA_API }!!)
}
if (JAVA_RUNTIME_CLASSES in candidateNames && JAVA_RUNTIME_RESOURCES in candidateNames && KOTLIN_RUNTIME in candidateNames) {
closestMatch(candidateValues.single { it?.name == KOTLIN_RUNTIME }!!)
}