[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:
committed by
Space Team
parent
fe0629ff8a
commit
b5e80fe060
+3
-5
@@ -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 */
|
||||
|
||||
+17
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user