[Gradle] Support sources publication as variants in ExternalKotlinTarget
^KT-36943
This commit is contained in:
+15
@@ -68,6 +68,15 @@ fun KotlinMultiplatformExtension.androidTargetPrototype(): PrototypeAndroidTarge
|
|||||||
configuration.attributes.attribute(AgpVersionAttr.ATTRIBUTE, project.objects.named("7.4.0-beta02")) /* For demo */
|
configuration.attributes.attribute(AgpVersionAttr.ATTRIBUTE, project.objects.named("7.4.0-beta02")) /* For demo */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Configure runtimeElements configuration attributes (project to project dependency)
|
||||||
|
In this example we hardcoded AGP version 7.4.0-beta02 as demo
|
||||||
|
*/
|
||||||
|
sourcesElements.configure { _, configuration ->
|
||||||
|
configuration.attributes.attribute(TARGET_JVM_ENVIRONMENT_ATTRIBUTE, project.objects.named(TargetJvmEnvironment.ANDROID))
|
||||||
|
configuration.attributes.attribute(AgpVersionAttr.ATTRIBUTE, project.objects.named("7.4.0-beta02")) /* For demo */
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Configure published configurations (maven publication):
|
Configure published configurations (maven publication):
|
||||||
We override KotlinPlatformType to be androidJvm for now (to be discussed w/ Google later)
|
We override KotlinPlatformType to be androidJvm for now (to be discussed w/ Google later)
|
||||||
@@ -84,6 +93,12 @@ fun KotlinMultiplatformExtension.androidTargetPrototype(): PrototypeAndroidTarge
|
|||||||
configuration.attributes.attribute(TARGET_JVM_ENVIRONMENT_ATTRIBUTE, project.objects.named(TargetJvmEnvironment.ANDROID))
|
configuration.attributes.attribute(TARGET_JVM_ENVIRONMENT_ATTRIBUTE, project.objects.named(TargetJvmEnvironment.ANDROID))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourcesElementsPublished.configure { _, configuration ->
|
||||||
|
/* TODO w/ Google: Find a way to deprecate this attribute */
|
||||||
|
configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm)
|
||||||
|
configuration.attributes.attribute(TARGET_JVM_ENVIRONMENT_ATTRIBUTE, project.objects.named(TargetJvmEnvironment.ANDROID))
|
||||||
|
}
|
||||||
|
|
||||||
configureIdeImport {
|
configureIdeImport {
|
||||||
registerDependencyResolver(
|
registerDependencyResolver(
|
||||||
AndroidBootClasspathIdeDependencyResolver(project),
|
AndroidBootClasspathIdeDependencyResolver(project),
|
||||||
|
|||||||
+5
@@ -47,6 +47,11 @@ internal class ExternalKotlinTargetComponent(
|
|||||||
override val defaultArtifactId: String
|
override val defaultArtifactId: String
|
||||||
get() = dashSeparatedName(target.project.name, target.name.toLowerCase())
|
get() = dashSeparatedName(target.project.name, target.name.toLowerCase())
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
message = "Sources artifacts are now published as separate variant " +
|
||||||
|
"use target.sourcesElementsConfigurationName to obtain necessary information",
|
||||||
|
replaceWith = ReplaceWith("target.sourcesElementsConfigurationName")
|
||||||
|
)
|
||||||
override val sourcesArtifacts: Set<PublishArtifact>
|
override val sourcesArtifacts: Set<PublishArtifact>
|
||||||
get() = emptySet()
|
get() = emptySet()
|
||||||
|
|
||||||
|
|||||||
+12
@@ -24,8 +24,10 @@ interface ExternalKotlinTargetDescriptor<T : DecoratedExternalKotlinTarget> {
|
|||||||
|
|
||||||
val apiElements: ExternalKotlinTargetConfigurationDescriptor<T>
|
val apiElements: ExternalKotlinTargetConfigurationDescriptor<T>
|
||||||
val runtimeElements: ExternalKotlinTargetConfigurationDescriptor<T>
|
val runtimeElements: ExternalKotlinTargetConfigurationDescriptor<T>
|
||||||
|
val sourcesElements: ExternalKotlinTargetConfigurationDescriptor<T>
|
||||||
val apiElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>
|
val apiElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>
|
||||||
val runtimeElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>
|
val runtimeElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>
|
||||||
|
val sourcesElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>
|
||||||
|
|
||||||
val configure: ((T) -> Unit)?
|
val configure: ((T) -> Unit)?
|
||||||
val configureIdeImport: (IdeMultiplatformImport.() -> Unit)?
|
val configureIdeImport: (IdeMultiplatformImport.() -> Unit)?
|
||||||
@@ -50,12 +52,18 @@ class ExternalKotlinTargetDescriptorBuilder<T : DecoratedExternalKotlinTarget> i
|
|||||||
val runtimeElements: ExternalKotlinTargetConfigurationDescriptorBuilder<T> =
|
val runtimeElements: ExternalKotlinTargetConfigurationDescriptorBuilder<T> =
|
||||||
ExternalKotlinTargetConfigurationDescriptorBuilder()
|
ExternalKotlinTargetConfigurationDescriptorBuilder()
|
||||||
|
|
||||||
|
val sourcesElements: ExternalKotlinTargetConfigurationDescriptorBuilder<T> =
|
||||||
|
ExternalKotlinTargetConfigurationDescriptorBuilder()
|
||||||
|
|
||||||
val apiElementsPublished: ExternalKotlinTargetConfigurationDescriptorBuilder<T> =
|
val apiElementsPublished: ExternalKotlinTargetConfigurationDescriptorBuilder<T> =
|
||||||
ExternalKotlinTargetConfigurationDescriptorBuilder()
|
ExternalKotlinTargetConfigurationDescriptorBuilder()
|
||||||
|
|
||||||
val runtimeElementsPublished: ExternalKotlinTargetConfigurationDescriptorBuilder<T> =
|
val runtimeElementsPublished: ExternalKotlinTargetConfigurationDescriptorBuilder<T> =
|
||||||
ExternalKotlinTargetConfigurationDescriptorBuilder()
|
ExternalKotlinTargetConfigurationDescriptorBuilder()
|
||||||
|
|
||||||
|
val sourcesElementsPublished: ExternalKotlinTargetConfigurationDescriptorBuilder<T> =
|
||||||
|
ExternalKotlinTargetConfigurationDescriptorBuilder()
|
||||||
|
|
||||||
var configure: ((T) -> Unit)? = null
|
var configure: ((T) -> Unit)? = null
|
||||||
|
|
||||||
fun configure(action: (T) -> Unit) {
|
fun configure(action: (T) -> Unit) {
|
||||||
@@ -78,8 +86,10 @@ class ExternalKotlinTargetDescriptorBuilder<T : DecoratedExternalKotlinTarget> i
|
|||||||
targetFactory = targetFactory,
|
targetFactory = targetFactory,
|
||||||
apiElements = apiElements.build(),
|
apiElements = apiElements.build(),
|
||||||
runtimeElements = runtimeElements.build(),
|
runtimeElements = runtimeElements.build(),
|
||||||
|
sourcesElements = sourcesElements.build(),
|
||||||
apiElementsPublished = apiElementsPublished.build(),
|
apiElementsPublished = apiElementsPublished.build(),
|
||||||
runtimeElementsPublished = runtimeElementsPublished.build(),
|
runtimeElementsPublished = runtimeElementsPublished.build(),
|
||||||
|
sourcesElementsPublished = sourcesElementsPublished.build(),
|
||||||
configure = configure,
|
configure = configure,
|
||||||
configureIdeImport = configureIdeImport
|
configureIdeImport = configureIdeImport
|
||||||
)
|
)
|
||||||
@@ -91,8 +101,10 @@ private data class ExternalKotlinTargetDescriptorImpl<T : DecoratedExternalKotli
|
|||||||
override val targetFactory: TargetFactory<T>,
|
override val targetFactory: TargetFactory<T>,
|
||||||
override val apiElements: ExternalKotlinTargetConfigurationDescriptor<T>,
|
override val apiElements: ExternalKotlinTargetConfigurationDescriptor<T>,
|
||||||
override val runtimeElements: ExternalKotlinTargetConfigurationDescriptor<T>,
|
override val runtimeElements: ExternalKotlinTargetConfigurationDescriptor<T>,
|
||||||
|
override val sourcesElements: ExternalKotlinTargetConfigurationDescriptor<T>,
|
||||||
override val apiElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>,
|
override val apiElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>,
|
||||||
override val runtimeElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>,
|
override val runtimeElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>,
|
||||||
|
override val sourcesElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>,
|
||||||
override val configure: ((T) -> Unit)?,
|
override val configure: ((T) -> Unit)?,
|
||||||
override val configureIdeImport: (IdeMultiplatformImport.() -> Unit)?,
|
override val configureIdeImport: (IdeMultiplatformImport.() -> Unit)?,
|
||||||
) : ExternalKotlinTargetDescriptor<T>
|
) : ExternalKotlinTargetDescriptor<T>
|
||||||
|
|||||||
+5
@@ -28,8 +28,10 @@ internal class ExternalKotlinTargetImpl internal constructor(
|
|||||||
val defaultConfiguration: Configuration,
|
val defaultConfiguration: Configuration,
|
||||||
val apiElementsConfiguration: Configuration,
|
val apiElementsConfiguration: Configuration,
|
||||||
val runtimeElementsConfiguration: Configuration,
|
val runtimeElementsConfiguration: Configuration,
|
||||||
|
val sourcesElementsConfiguration: Configuration,
|
||||||
val apiElementsPublishedConfiguration: Configuration,
|
val apiElementsPublishedConfiguration: Configuration,
|
||||||
val runtimeElementsPublishedConfiguration: Configuration,
|
val runtimeElementsPublishedConfiguration: Configuration,
|
||||||
|
val sourcesElementsPublishedConfiguration: Configuration,
|
||||||
val kotlinTargetComponent: ExternalKotlinTargetComponent,
|
val kotlinTargetComponent: ExternalKotlinTargetComponent,
|
||||||
private val artifactsTaskLocator: ArtifactsTaskLocator,
|
private val artifactsTaskLocator: ArtifactsTaskLocator,
|
||||||
) : InternalKotlinTarget {
|
) : InternalKotlinTarget {
|
||||||
@@ -65,6 +67,9 @@ internal class ExternalKotlinTargetImpl internal constructor(
|
|||||||
override val runtimeElementsConfigurationName: String
|
override val runtimeElementsConfigurationName: String
|
||||||
get() = runtimeElementsConfiguration.name
|
get() = runtimeElementsConfiguration.name
|
||||||
|
|
||||||
|
override val sourcesElementsConfigurationName: String
|
||||||
|
get() = sourcesElementsConfiguration.name
|
||||||
|
|
||||||
@InternalKotlinGradlePluginApi
|
@InternalKotlinGradlePluginApi
|
||||||
override val kotlinComponents: Set<KotlinTargetComponent> = setOf(kotlinTargetComponent)
|
override val kotlinComponents: Set<KotlinTargetComponent> = setOf(kotlinTargetComponent)
|
||||||
|
|
||||||
|
|||||||
+18
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.gradle.ExternalKotlinTargetApi
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||||
import org.jetbrains.kotlin.gradle.plugin.ide.kotlinIdeMultiplatformImport
|
import org.jetbrains.kotlin.gradle.plugin.ide.kotlinIdeMultiplatformImport
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.configureSourcesPublicationAttributes
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.markConsumable
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.markConsumable
|
||||||
import org.jetbrains.kotlin.gradle.plugin.usesPlatformOf
|
import org.jetbrains.kotlin.gradle.plugin.usesPlatformOf
|
||||||
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
|
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
|
||||||
@@ -28,6 +29,7 @@ fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExter
|
|||||||
val defaultConfiguration = project.configurations.maybeCreate(lowerCamelCaseName(descriptor.targetName, "default"))
|
val defaultConfiguration = project.configurations.maybeCreate(lowerCamelCaseName(descriptor.targetName, "default"))
|
||||||
val apiElementsConfiguration = project.configurations.maybeCreate(lowerCamelCaseName(descriptor.targetName, "apiElements"))
|
val apiElementsConfiguration = project.configurations.maybeCreate(lowerCamelCaseName(descriptor.targetName, "apiElements"))
|
||||||
val runtimeElementsConfiguration = project.configurations.maybeCreate(lowerCamelCaseName(descriptor.targetName, "runtimeElements"))
|
val runtimeElementsConfiguration = project.configurations.maybeCreate(lowerCamelCaseName(descriptor.targetName, "runtimeElements"))
|
||||||
|
val sourcesElementsConfiguration = project.configurations.maybeCreate(lowerCamelCaseName(descriptor.targetName, "sourcesElements"))
|
||||||
|
|
||||||
val apiElementsPublishedConfiguration =
|
val apiElementsPublishedConfiguration =
|
||||||
project.configurations.maybeCreate(lowerCamelCaseName(descriptor.targetName, "apiElements-published"))
|
project.configurations.maybeCreate(lowerCamelCaseName(descriptor.targetName, "apiElements-published"))
|
||||||
@@ -35,6 +37,9 @@ fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExter
|
|||||||
val runtimeElementsPublishedConfiguration =
|
val runtimeElementsPublishedConfiguration =
|
||||||
project.configurations.maybeCreate(lowerCamelCaseName(descriptor.targetName, "runtimeElements-published"))
|
project.configurations.maybeCreate(lowerCamelCaseName(descriptor.targetName, "runtimeElements-published"))
|
||||||
|
|
||||||
|
val sourcesElementsPublishedConfiguration =
|
||||||
|
project.configurations.maybeCreate(lowerCamelCaseName(descriptor.targetName, "sourcesElements-published"))
|
||||||
|
|
||||||
val kotlinTargetComponent = ExternalKotlinTargetComponent(
|
val kotlinTargetComponent = ExternalKotlinTargetComponent(
|
||||||
ExternalKotlinTargetComponent.TargetProvider.byTargetName(this, descriptor.targetName)
|
ExternalKotlinTargetComponent.TargetProvider.byTargetName(this, descriptor.targetName)
|
||||||
)
|
)
|
||||||
@@ -51,8 +56,10 @@ fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExter
|
|||||||
defaultConfiguration = defaultConfiguration,
|
defaultConfiguration = defaultConfiguration,
|
||||||
apiElementsConfiguration = apiElementsConfiguration,
|
apiElementsConfiguration = apiElementsConfiguration,
|
||||||
runtimeElementsConfiguration = runtimeElementsConfiguration,
|
runtimeElementsConfiguration = runtimeElementsConfiguration,
|
||||||
|
sourcesElementsConfiguration = sourcesElementsConfiguration,
|
||||||
apiElementsPublishedConfiguration = apiElementsPublishedConfiguration,
|
apiElementsPublishedConfiguration = apiElementsPublishedConfiguration,
|
||||||
runtimeElementsPublishedConfiguration = runtimeElementsPublishedConfiguration,
|
runtimeElementsPublishedConfiguration = runtimeElementsPublishedConfiguration,
|
||||||
|
sourcesElementsPublishedConfiguration = sourcesElementsPublishedConfiguration,
|
||||||
kotlinTargetComponent = kotlinTargetComponent,
|
kotlinTargetComponent = kotlinTargetComponent,
|
||||||
artifactsTaskLocator = artifactsTaskLocator
|
artifactsTaskLocator = artifactsTaskLocator
|
||||||
)
|
)
|
||||||
@@ -61,14 +68,19 @@ fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExter
|
|||||||
target.setupApiElements(apiElementsPublishedConfiguration)
|
target.setupApiElements(apiElementsPublishedConfiguration)
|
||||||
target.setupRuntimeElements(runtimeElementsConfiguration)
|
target.setupRuntimeElements(runtimeElementsConfiguration)
|
||||||
target.setupRuntimeElements(runtimeElementsPublishedConfiguration)
|
target.setupRuntimeElements(runtimeElementsPublishedConfiguration)
|
||||||
|
target.setupSourcesElements(sourcesElementsConfiguration)
|
||||||
|
target.setupSourcesElements(sourcesElementsPublishedConfiguration)
|
||||||
apiElementsConfiguration.markConsumable()
|
apiElementsConfiguration.markConsumable()
|
||||||
runtimeElementsConfiguration.markConsumable()
|
runtimeElementsConfiguration.markConsumable()
|
||||||
|
sourcesElementsConfiguration.markConsumable()
|
||||||
|
|
||||||
/* Those configurations can not be resolved but also not consumed (not suitable for project to proejct dependencies */
|
/* Those configurations can not be resolved but also not consumed (not suitable for project to proejct dependencies */
|
||||||
apiElementsPublishedConfiguration.isCanBeConsumed = false
|
apiElementsPublishedConfiguration.isCanBeConsumed = false
|
||||||
apiElementsPublishedConfiguration.isCanBeResolved = false
|
apiElementsPublishedConfiguration.isCanBeResolved = false
|
||||||
runtimeElementsPublishedConfiguration.isCanBeResolved = false
|
runtimeElementsPublishedConfiguration.isCanBeResolved = false
|
||||||
runtimeElementsPublishedConfiguration.isCanBeConsumed = false
|
runtimeElementsPublishedConfiguration.isCanBeConsumed = false
|
||||||
|
sourcesElementsPublishedConfiguration.isCanBeResolved = false
|
||||||
|
sourcesElementsPublishedConfiguration.isCanBeConsumed = false
|
||||||
|
|
||||||
val decorated = descriptor.targetFactory.create(DecoratedExternalKotlinTarget.Delegate(target))
|
val decorated = descriptor.targetFactory.create(DecoratedExternalKotlinTarget.Delegate(target))
|
||||||
target.onCreated()
|
target.onCreated()
|
||||||
@@ -76,8 +88,10 @@ fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExter
|
|||||||
descriptor.configure?.invoke(decorated)
|
descriptor.configure?.invoke(decorated)
|
||||||
descriptor.apiElements.configure?.invoke(decorated, apiElementsConfiguration)
|
descriptor.apiElements.configure?.invoke(decorated, apiElementsConfiguration)
|
||||||
descriptor.runtimeElements.configure?.invoke(decorated, runtimeElementsConfiguration)
|
descriptor.runtimeElements.configure?.invoke(decorated, runtimeElementsConfiguration)
|
||||||
|
descriptor.sourcesElements.configure?.invoke(decorated, sourcesElementsConfiguration)
|
||||||
descriptor.apiElementsPublished.configure?.invoke(decorated, apiElementsPublishedConfiguration)
|
descriptor.apiElementsPublished.configure?.invoke(decorated, apiElementsPublishedConfiguration)
|
||||||
descriptor.runtimeElementsPublished.configure?.invoke(decorated, runtimeElementsPublishedConfiguration)
|
descriptor.runtimeElementsPublished.configure?.invoke(decorated, runtimeElementsPublishedConfiguration)
|
||||||
|
descriptor.sourcesElementsPublished.configure?.invoke(decorated, sourcesElementsPublishedConfiguration)
|
||||||
descriptor.configureIdeImport?.invoke(project.kotlinIdeMultiplatformImport)
|
descriptor.configureIdeImport?.invoke(project.kotlinIdeMultiplatformImport)
|
||||||
|
|
||||||
targets.add(decorated)
|
targets.add(decorated)
|
||||||
@@ -103,3 +117,7 @@ private fun ExternalKotlinTargetImpl.setupRuntimeElements(configuration: Configu
|
|||||||
configuration.attributes.attribute(Usage.USAGE_ATTRIBUTE, KotlinUsages.producerRuntimeUsage(this))
|
configuration.attributes.attribute(Usage.USAGE_ATTRIBUTE, KotlinUsages.producerRuntimeUsage(this))
|
||||||
configuration.attributes.attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY))
|
configuration.attributes.attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun ExternalKotlinTargetImpl.setupSourcesElements(configuration: Configuration) {
|
||||||
|
configuration.configureSourcesPublicationAttributes(this)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user