Apply resolution strategy before applying KGP in resources tests

^KT-66133
This commit is contained in:
Timofey Solonin
2024-03-11 16:45:41 +01:00
committed by Space Team
parent 1849f17228
commit 5873127342
@@ -33,6 +33,8 @@ import org.jetbrains.kotlin.util.assertThrows
import org.junit.Test import org.junit.Test
import java.io.File import java.io.File
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
class KotlinTargetVariantResourcesResolutionTests { class KotlinTargetVariantResourcesResolutionTests {
@@ -356,7 +358,10 @@ class KotlinTargetVariantResourcesResolutionTests {
fun `test KT66393 - resolving resources with java-api dependencies in native configuration`() { fun `test KT66393 - resolving resources with java-api dependencies in native configuration`() {
val resolutionStrategy = KotlinTargetResourcesResolutionStrategy.ResourcesConfiguration val resolutionStrategy = KotlinTargetResourcesResolutionStrategy.ResourcesConfiguration
val rootProject = buildProject() val rootProject = buildProject()
val producer = rootProject.createSubproject("producer") { val producer = rootProject.createSubproject(
"producer",
resolutionStrategy = resolutionStrategy,
) {
kotlin { kotlin {
linuxArm64() linuxArm64()
sourceSets.commonMain { sourceSets.commonMain {
@@ -364,10 +369,12 @@ class KotlinTargetVariantResourcesResolutionTests {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0")
} }
} }
setMppResourcesResolutionStrategy(resolutionStrategy)
} }
} }
val consumer = rootProject.createSubproject("consumer") { val consumer = rootProject.createSubproject(
"consumer",
resolutionStrategy = resolutionStrategy,
) {
kotlin { kotlin {
linuxArm64() linuxArm64()
sourceSets.commonMain { sourceSets.commonMain {
@@ -375,7 +382,6 @@ class KotlinTargetVariantResourcesResolutionTests {
implementation(project(":${producer.name}")) implementation(project(":${producer.name}"))
} }
} }
setMppResourcesResolutionStrategy(resolutionStrategy)
} }
} }
@@ -390,6 +396,23 @@ class KotlinTargetVariantResourcesResolutionTests {
) )
} }
@Test
fun `test resources configuration - only exists in projects with resources configuration strategy`() {
val rootProject = buildProject()
assertNotNull(
rootProject.createSubproject(
"resourcesConfiguration",
resolutionStrategy = KotlinTargetResourcesResolutionStrategy.ResourcesConfiguration,
) { kotlin { linuxArm64() } }.configurations.findByName("linuxArm64ResourcesPath")
)
assertNull(
rootProject.createSubproject(
"variantReselection",
resolutionStrategy = KotlinTargetResourcesResolutionStrategy.VariantReselection,
) { kotlin { linuxArm64() } }.configurations.findByName("linuxArm64ResourcesPath")
)
}
private fun dependencyScopesWithResources(): List<DependencyScopeProvider> { private fun dependencyScopesWithResources(): List<DependencyScopeProvider> {
return listOf( return listOf(
{ this::implementation }, { this::implementation },
@@ -487,7 +510,6 @@ class KotlinTargetVariantResourcesResolutionTests {
dependencyScope = dependencyScope, dependencyScope = dependencyScope,
strategy = resolutionStrategy, strategy = resolutionStrategy,
assert = { consumer: Project, producer: Project -> assert = { consumer: Project, producer: Project ->
consumer.setMppResourcesResolutionStrategy(resolutionStrategy)
assertEquals( assertEquals(
expectedResult(consumer, producer), expectedResult(consumer, producer),
filterResolvedFiles( filterResolvedFiles(
@@ -507,12 +529,15 @@ class KotlinTargetVariantResourcesResolutionTests {
assert: (consumer: Project, producer: Project) -> Unit, assert: (consumer: Project, producer: Project) -> Unit,
) { ) {
val rootProject = buildProject() val rootProject = buildProject()
val producer = rootProject.createSubproject("producer") { val producer = rootProject.createSubproject(
"producer",
resolutionStrategy = strategy,
) {
kotlin { producerTarget() } kotlin { producerTarget() }
} }
val consumer = rootProject.createSubproject( val consumer = rootProject.createSubproject(
"consumer", "consumer",
preApplyCode = { setMppResourcesResolutionStrategy(strategy) } resolutionStrategy = strategy,
) { ) {
kotlin { kotlin {
consumerTarget() consumerTarget()
@@ -542,9 +567,9 @@ class KotlinTargetVariantResourcesResolutionTests {
val rootProject = buildProject() val rootProject = buildProject()
val producer = rootProject.createSubproject( val producer = rootProject.createSubproject(
"producer", "producer",
resolutionStrategy = resolutionStrategy,
preApplyCode = { preApplyCode = {
enableMppResourcesPublication(true) enableMppResourcesPublication(true)
setMppResourcesResolutionStrategy(resolutionStrategy)
} }
) { ) {
kotlin { targetProvider() } kotlin { targetProvider() }
@@ -552,9 +577,9 @@ class KotlinTargetVariantResourcesResolutionTests {
val middle = rootProject.createSubproject( val middle = rootProject.createSubproject(
"middle", "middle",
resolutionStrategy = resolutionStrategy,
preApplyCode = { preApplyCode = {
enableMppResourcesPublication(middlePublishesResources) enableMppResourcesPublication(middlePublishesResources)
setMppResourcesResolutionStrategy(resolutionStrategy)
} }
) { ) {
kotlin { kotlin {
@@ -569,9 +594,9 @@ class KotlinTargetVariantResourcesResolutionTests {
val consumer = rootProject.createSubproject( val consumer = rootProject.createSubproject(
"consumer", "consumer",
resolutionStrategy = resolutionStrategy,
preApplyCode = { preApplyCode = {
enableMppResourcesPublication(consumerPublishesResources) enableMppResourcesPublication(consumerPublishesResources)
setMppResourcesResolutionStrategy(resolutionStrategy)
} }
) { ) {
kotlin { kotlin {
@@ -581,7 +606,6 @@ class KotlinTargetVariantResourcesResolutionTests {
dependencyScope()(dependencies.project(":${middle.name}")) dependencyScope()(dependencies.project(":${middle.name}"))
} }
} }
setMppResourcesResolutionStrategy(resolutionStrategy)
} }
} }
@@ -605,14 +629,18 @@ class KotlinTargetVariantResourcesResolutionTests {
private fun ProjectInternal.createSubproject( private fun ProjectInternal.createSubproject(
name: String, name: String,
preApplyCode: Project.() -> Unit = {}, preApplyCode: Project.() -> Unit = { },
resolutionStrategy: KotlinTargetResourcesResolutionStrategy,
code: Project.() -> Unit = {}, code: Project.() -> Unit = {},
) = buildProjectWithMPPAndStdlib( ) = buildProjectWithMPPAndStdlib(
projectBuilder = { projectBuilder = {
withParent(this@createSubproject) withParent(this@createSubproject)
withName(name) withName(name)
}, },
preApplyCode = preApplyCode, preApplyCode = {
preApplyCode()
setMppResourcesResolutionStrategy(resolutionStrategy)
},
code = code, code = code,
) )