[Gradle] Mark sourcesElements configurations as non-consumable

In case if `isSourcesPublishable` set to false.

^KT-57652 Verification Pending
This commit is contained in:
Anton Lakotka
2023-03-29 16:18:56 +02:00
committed by Space Team
parent 0b07a20a70
commit 118c62cfbb
2 changed files with 22 additions and 13 deletions
@@ -201,16 +201,13 @@ abstract class AbstractKotlinTargetConfigurator<KotlinTargetType : KotlinTarget>
} }
} }
project.whenEvaluated { configurations.maybeCreate(target.sourcesElementsConfigurationName).apply {
if (target.internal.isSourcesPublishable) { description = "Source files of main compilation of ${target.name}."
configurations.maybeCreate(target.sourcesElementsConfigurationName).apply { isVisible = false
description = "Source files of main compilation of ${target.name}." isCanBeResolved = false
isVisible = false isCanBeConsumed = true
isCanBeResolved = false configureSourcesPublicationAttributes(target)
isCanBeConsumed = true project.whenEvaluated { isCanBeConsumed = target.internal.isSourcesPublishable }
configureSourcesPublicationAttributes(target)
}
}
} }
if (createTestCompilation) { if (createTestCompilation) {
@@ -202,14 +202,26 @@ class MppPublicationTest {
} }
@Test @Test
fun `test that no sourcesElements should be exposed when sources are not published`() { fun `test that no sourcesElements should be consumable when sources are published`() {
kotlin.linuxX64("linux")
kotlin.withSourcesJar(publish = true)
project.evaluate()
kotlin.targets.forEach {
val sourcesElements = project.configurations.getByName(it.sourcesElementsConfigurationName)
if (!sourcesElements.isCanBeConsumed) fail("Configuration '${it.sourcesElementsConfigurationName}' should be consumable")
}
}
@Test
fun `test that no sourcesElements should be consumable when sources are not published`() {
kotlin.linuxX64("linux") kotlin.linuxX64("linux")
kotlin.withSourcesJar(publish = false) kotlin.withSourcesJar(publish = false)
project.evaluate() project.evaluate()
kotlin.targets.forEach { kotlin.targets.forEach {
if (it.sourcesElementsConfigurationName in project.configurations.names) val sourcesElements = project.configurations.getByName(it.sourcesElementsConfigurationName)
fail("Configuration '${it.sourcesElementsConfigurationName}' should not be created") if (sourcesElements.isCanBeConsumed) fail("Configuration '${it.sourcesElementsConfigurationName}' should not be consumable")
} }
} }