[Gradle] Add mavenScope parameter to createSourcesJarAndUsageContextIfPublishable

^KT-55881 Verification Pending
This commit is contained in:
Anton Lakotka
2023-02-21 08:23:42 +01:00
committed by Space Team
parent f8e1b51f04
commit 1dd9751f99
3 changed files with 15 additions and 1 deletions
@@ -142,6 +142,7 @@ abstract class AbstractKotlinTarget(
classifierPrefix: String? = null,
sourcesElementsConfigurationName: String = this.sourcesElementsConfigurationName,
overrideConfigurationAttributes: AttributeContainer? = null,
mavenScope: KotlinUsageContext.MavenScope? = null,
): DefaultKotlinUsageContext? {
// We want to create task anyway, even if sources are not going to be published by KGP
// So users or other plugins can still use it
@@ -160,6 +161,7 @@ abstract class AbstractKotlinTarget(
compilation = producingCompilation,
dependencyConfigurationName = sourcesElementsConfigurationName,
overrideConfigurationAttributes = overrideConfigurationAttributes,
mavenScope = mavenScope,
includeIntoProjectStructureMetadata = false,
publishOnlyIf = { isSourcesPublishable }
)
@@ -86,7 +86,8 @@ constructor(
createSourcesJarAndUsageContextIfPublishable(
mainCompilation,
componentName,
dashSeparatedName(targetName.toLowerCaseAsciiOnly())
dashSeparatedName(targetName.toLowerCaseAsciiOnly()),
mavenScope = KotlinUsageContext.MavenScope.RUNTIME
)
)
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.internal
import org.jetbrains.kotlin.gradle.util.addBuildEventsListenerRegistryMock
import org.jetbrains.kotlin.gradle.util.disableLegacyWarning
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
import kotlin.test.*
class MppPublicationTest {
@@ -128,6 +129,16 @@ class MppPublicationTest {
}
}
@Test
fun `sources elements should not have any dependencies`() {
project.evaluate()
project.configurations
.filter { it.name.toLowerCaseAsciiOnly().contains("sourceselements") }
.forEach { configuration ->
if (configuration.dependencies.isNotEmpty()) fail("Configuration $configuration should not have dependencies")
}
}
@Test
fun `sourcesJar task should be available during configuration time`() {