[Gradle] Keep kotlinSourcesJar in Kotlin/JVM projects

After introducing sourcesElements for Multiplatform projects the task
was not registered. As result of an assumption that Java Gradle Plugin
is taking care of sources publication. But in fact some users can
still rely on Kotlin's `kotlinSourceJar` task instead of JGP's
`sourcesJar`. This look inconsistent and is a matter of a different
issue: KT-54207

^KT-36943
This commit is contained in:
Anton Lakotka
2022-12-01 09:15:23 +01:00
committed by teamcity
parent 51c33333ea
commit 5023ccc724
@@ -133,11 +133,13 @@ abstract class AbstractKotlinTarget(
classifierPrefix: String? = null,
sourcesElementsConfigurationName: String = this.sourcesElementsConfigurationName,
): PublishArtifact? {
val sourcesJarTask = sourcesJarTask(producingCompilation, componentName, artifactNameAppendix)
// If sourcesElements configuration not found, don't create artifact.
// This can happen in pure JVM plugin where source publication is delegated to Java Gradle Plugin
// This can happen in pure JVM plugin where source publication is delegated to Java Gradle Plugin.
// But we still want to have sourcesJarTask be registered
project.configurations.findByName(sourcesElementsConfigurationName) ?: return null
val sourcesJarTask = sourcesJarTask(producingCompilation, componentName, artifactNameAppendix)
val artifact = project.artifacts.add(sourcesElementsConfigurationName, sourcesJarTask) as ConfigurablePublishArtifact
artifact.classifier = dashSeparatedName(classifierPrefix, "sources")
return artifact