[Gradle] Add withSourcesJar to gradle dsl

* Each target can be configured to either publish or not its sources.
* For convenience withSourcesJar available also on kotlin multiplatform
  extension level. It then calls `withSourcesJar` for each target.

^KT-55881 In Progress
This commit is contained in:
Anton Lakotka
2023-02-08 19:51:53 +01:00
committed by Space Team
parent 4060cc2750
commit 1b3b83755e
4 changed files with 16 additions and 0 deletions
@@ -38,6 +38,8 @@ interface KotlinTarget : Named, HasAttributes {
val publishable: Boolean
fun withSourcesJar(publish: Boolean = true)
val components: Set<SoftwareComponent>
fun mavenPublication(action: MavenPublication.() -> Unit) = mavenPublication(Action { action(it) })
@@ -65,6 +65,10 @@ abstract class KotlinMultiplatformExtension(project: Project) :
fun metadata(configure: Action<KotlinOnlyTarget<KotlinMetadataCompilation<*>>>) = metadata { configure.execute(this) }
fun withSourcesJar(publish: Boolean = true) {
targets.all { withSourcesJar(publish) }
}
fun <T : KotlinTarget> targetFromPreset(
preset: KotlinTargetPreset<T>,
name: String = preset.name,
@@ -67,6 +67,11 @@ abstract class AbstractKotlinTarget(
override val publishable: Boolean
get() = true
internal var publishSources: Boolean = true
override fun withSourcesJar(publish: Boolean) {
publishSources = publish
}
@InternalKotlinGradlePluginApi
override val kotlinComponents: Set<KotlinTargetComponent> by lazy {
val mainCompilation = compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
@@ -58,6 +58,11 @@ internal class ExternalKotlinTargetImpl internal constructor(
artifactsTaskLocator.locate(this)
}
private var publishSources: Boolean = true
override fun withSourcesJar(publish: Boolean) {
publishSources = publish
}
override val artifactsTaskName: String
get() = artifactsTask.name