[Gradle] KotlinMultiplatformSourceSetConventions: Do not configure source sets in 'lazy' context

As source sets are not lazy. This avoids unnecessary exceptions
in user buildscripts.

^KT-60842 Verification Pending
This commit is contained in:
Sebastian Sellmair
2023-08-01 10:03:46 +02:00
committed by Space Team
parent fe0629ff8a
commit b5e80fe060
2 changed files with 20 additions and 5 deletions
@@ -55,17 +55,15 @@ interface KotlinMultiplatformSourceSetConventions {
operator fun NamedDomainObjectProvider<KotlinSourceSet>.invoke(
configure: KotlinSourceSet.() -> Unit,
) = configure(configure)
): Unit = get().run(configure)
fun NamedDomainObjectProvider<KotlinSourceSet>.dependencies(
handler: KotlinDependencyHandler.() -> Unit,
) = get().dependencies(handler)
): Unit = get().dependencies(handler)
fun NamedDomainObjectProvider<KotlinSourceSet>.languageSettings(
configure: LanguageSettingsBuilder.() -> Unit,
) = configure { sourceSet ->
sourceSet.languageSettings(configure)
}
): Unit = this { languageSettings(configure) }
}
/* Implementation */
@@ -51,6 +51,23 @@ class KotlinMultiplatformSourceSetConventionsTest {
}
}
@Test
fun `test - invoke - allows creating new source set in closure`() {
val project = buildProjectWithMPP()
project.multiplatformExtension.apply {
sourceSets.jvmMain {
/*
When done wrong, expect:
org.gradle.api.internal.AbstractMutationGuard$IllegalMutationException:
NamedDomainObjectContainer#create(String) on KotlinSourceSet container cannot be executed in the current context
*/
dependsOn(sourceSets.create("foo"))
}
assertEquals(setOf("foo"), sourceSets.jvmMain.get().dependsOn.map { it.name }.toSet())
}
}
@Test
fun `test - languageSettings`() {
val project = buildProjectWithMPP()