Fix metadata transformation for non-published dependencies, KT-32225

Fix dependencies that are added in non-published source sets, which were
omitted from the requested dependencies since their configurations were
not added to the extendsFrom set of the merged configurations.

Also, don't resolve both merged configurations (compile and runtime) in
GranularMetadataTransformation, as the IDE can anyway import only the
compile-scoped dependencies from api & implementation.

Issue #KT-32225 Fixed
This commit is contained in:
Sergey Igushkin
2019-07-02 16:10:26 +03:00
parent dbc8007c63
commit 4516902aaf
3 changed files with 94 additions and 6 deletions
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.gradle.internals.parseKotlinSourceSetMetadataFromXml
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinProjectStructureMetadata
import org.jetbrains.kotlin.gradle.plugin.mpp.ModuleDependencyIdentifier
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
import org.jetbrains.kotlin.gradle.util.checkedReplace
import org.jetbrains.kotlin.gradle.util.modify
import java.io.File
import java.util.zip.ZipFile
@@ -52,6 +53,77 @@ class HierarchicalMppIT : BaseGradleIT() {
}
}
@Test
fun testDependenciesInTests() {
publishThirdPartyLib(withGranularMetadata = true)
Project("my-lib-foo", gradleVersion, "hierarchical-mpp-published-modules").run {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
testDependencyTransformations { reports ->
val testApiTransformationReports =
reports.filter { report ->
report.groupAndModule.startsWith("com.example.thirdparty") &&
report.sourceSetName.let { it == "commonTest" || it == "jvmAndJsTest" }
}
testApiTransformationReports.forEach {
assertTrue("$it") { it.isExcluded } // should not be visible in test source sets
}
}
// --- Move the dependency from jvmAndJsMain to commonMain, expect that it is now propagated to commonTest:
gradleBuildScript().modify {
it.checkedReplace("api(\"com.example.thirdparty:third-party-lib:1.0\")", "//") + "\n" + """
dependencies {
"commonMainApi"("com.example.thirdparty:third-party-lib:1.0")
}
""".trimIndent()
}
testDependencyTransformations { reports ->
val testApiTransformationReports =
reports.filter { report ->
report.groupAndModule.startsWith("com.example.thirdparty") &&
report.sourceSetName.let { it == "commonTest" || it == "jvmAndJsTest" } &&
report.scope == "api"
}
testApiTransformationReports.forEach {
assertEquals(setOf("commonMain"), it.allVisibleSourceSets, "$it")
assertEquals(emptySet(), it.newVisibleSourceSets, "$it")
}
}
// --- Remove the dependency from commonMain, add it to commonTest to check that it is correctly picked from a non-published
// source set:
gradleBuildScript().modify {
it.checkedReplace("\"commonMainApi\"(\"com.example.thirdparty:third-party-lib:1.0\")", "//") + "\n" + """
dependencies {
"commonTestApi"("com.example.thirdparty:third-party-lib:1.0")
}
""".trimIndent()
}
testDependencyTransformations { reports ->
reports.single {
it.sourceSetName == "commonTest" && it.scope == "api" && it.groupAndModule.startsWith("com.example.thirdparty")
}.let {
assertEquals(setOf("commonMain"), it.allVisibleSourceSets)
assertEquals(setOf("commonMain"), it.newVisibleSourceSets)
}
reports.single {
it.sourceSetName == "jvmAndJsTest" && it.scope == "api" && it.groupAndModule.startsWith("com.example.thirdparty")
}.let {
assertEquals(setOf("commonMain"), it.allVisibleSourceSets)
assertEquals(emptySet(), it.newVisibleSourceSets)
}
}
}
}
@Test
fun testProjectDependencies() {
publishThirdPartyLib(withGranularMetadata = false)