[Gradle] ExternalTargetApi: Add sourcesElements-published and add this configuration to the published component
^KT-58109 In Progress
This commit is contained in:
committed by
Space Team
parent
aee9b7aae3
commit
3f1faa26ac
@@ -720,7 +720,9 @@ public class org/jetbrains/kotlin/gradle/plugin/mpp/external/DecoratedExternalKo
|
|||||||
public final fun getRuntimeElementsConfiguration ()Lorg/gradle/api/artifacts/Configuration;
|
public final fun getRuntimeElementsConfiguration ()Lorg/gradle/api/artifacts/Configuration;
|
||||||
public fun getRuntimeElementsConfigurationName ()Ljava/lang/String;
|
public fun getRuntimeElementsConfigurationName ()Ljava/lang/String;
|
||||||
public final fun getRuntimeElementsPublishedConfiguration ()Lorg/gradle/api/artifacts/Configuration;
|
public final fun getRuntimeElementsPublishedConfiguration ()Lorg/gradle/api/artifacts/Configuration;
|
||||||
|
public final fun getSourcesElementsConfiguration ()Lorg/gradle/api/artifacts/Configuration;
|
||||||
public fun getSourcesElementsConfigurationName ()Ljava/lang/String;
|
public fun getSourcesElementsConfigurationName ()Ljava/lang/String;
|
||||||
|
public final fun getSourcesElementsPublishedConfiguration ()Lorg/gradle/api/artifacts/Configuration;
|
||||||
public fun getTargetName ()Ljava/lang/String;
|
public fun getTargetName ()Ljava/lang/String;
|
||||||
public fun getUseDisambiguationClassifierAsSourceSetNamePrefix ()Z
|
public fun getUseDisambiguationClassifierAsSourceSetNamePrefix ()Z
|
||||||
public fun isSourcesPublishable ()Z
|
public fun isSourcesPublishable ()Z
|
||||||
@@ -799,6 +801,7 @@ public abstract interface class org/jetbrains/kotlin/gradle/plugin/mpp/external/
|
|||||||
public abstract fun getRuntimeElements ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetConfigurationDescriptor;
|
public abstract fun getRuntimeElements ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetConfigurationDescriptor;
|
||||||
public abstract fun getRuntimeElementsPublished ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetConfigurationDescriptor;
|
public abstract fun getRuntimeElementsPublished ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetConfigurationDescriptor;
|
||||||
public abstract fun getSourcesElements ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetConfigurationDescriptor;
|
public abstract fun getSourcesElements ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetConfigurationDescriptor;
|
||||||
|
public abstract fun getSourcesElementsPublished ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetConfigurationDescriptor;
|
||||||
public abstract fun getTargetFactory ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetDescriptor$TargetFactory;
|
public abstract fun getTargetFactory ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetDescriptor$TargetFactory;
|
||||||
public abstract fun getTargetName ()Ljava/lang/String;
|
public abstract fun getTargetName ()Ljava/lang/String;
|
||||||
}
|
}
|
||||||
@@ -816,6 +819,7 @@ public final class org/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotli
|
|||||||
public final fun getRuntimeElements ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetConfigurationDescriptorBuilder;
|
public final fun getRuntimeElements ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetConfigurationDescriptorBuilder;
|
||||||
public final fun getRuntimeElementsPublished ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetConfigurationDescriptorBuilder;
|
public final fun getRuntimeElementsPublished ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetConfigurationDescriptorBuilder;
|
||||||
public final fun getSourcesElements ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetConfigurationDescriptorBuilder;
|
public final fun getSourcesElements ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetConfigurationDescriptorBuilder;
|
||||||
|
public final fun getSourcesElementsPublished ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetConfigurationDescriptorBuilder;
|
||||||
public final fun getTargetFactory ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetDescriptor$TargetFactory;
|
public final fun getTargetFactory ()Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/ExternalKotlinTargetDescriptor$TargetFactory;
|
||||||
public final fun getTargetName ()Ljava/lang/String;
|
public final fun getTargetName ()Ljava/lang/String;
|
||||||
public final fun setPlatformType (Lorg/jetbrains/kotlin/gradle/plugin/KotlinPlatformType;)V
|
public final fun setPlatformType (Lorg/jetbrains/kotlin/gradle/plugin/KotlinPlatformType;)V
|
||||||
|
|||||||
+11
-1
@@ -40,7 +40,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.InternalKotlinTarget
|
|||||||
*/
|
*/
|
||||||
@ExternalKotlinTargetApi
|
@ExternalKotlinTargetApi
|
||||||
open class DecoratedExternalKotlinTarget internal constructor(
|
open class DecoratedExternalKotlinTarget internal constructor(
|
||||||
internal val delegate: ExternalKotlinTargetImpl
|
internal val delegate: ExternalKotlinTargetImpl,
|
||||||
) : InternalKotlinTarget by delegate {
|
) : InternalKotlinTarget by delegate {
|
||||||
constructor(delegate: Delegate) : this(delegate.impl)
|
constructor(delegate: Delegate) : this(delegate.impl)
|
||||||
|
|
||||||
@@ -50,10 +50,20 @@ open class DecoratedExternalKotlinTarget internal constructor(
|
|||||||
|
|
||||||
val runtimeElementsConfiguration: Configuration = delegate.runtimeElementsConfiguration
|
val runtimeElementsConfiguration: Configuration = delegate.runtimeElementsConfiguration
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.9.20
|
||||||
|
*/
|
||||||
|
val sourcesElementsConfiguration: Configuration = delegate.sourcesElementsConfiguration
|
||||||
|
|
||||||
val apiElementsPublishedConfiguration: Configuration = delegate.apiElementsPublishedConfiguration
|
val apiElementsPublishedConfiguration: Configuration = delegate.apiElementsPublishedConfiguration
|
||||||
|
|
||||||
val runtimeElementsPublishedConfiguration: Configuration = delegate.runtimeElementsPublishedConfiguration
|
val runtimeElementsPublishedConfiguration: Configuration = delegate.runtimeElementsPublishedConfiguration
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.9.20
|
||||||
|
*/
|
||||||
|
val sourcesElementsPublishedConfiguration: Configuration = delegate.sourcesElementsPublishedConfiguration
|
||||||
|
|
||||||
internal val logger: Logger = delegate.logger
|
internal val logger: Logger = delegate.logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
@@ -37,6 +37,11 @@ interface ExternalKotlinTargetDescriptor<T : DecoratedExternalKotlinTarget> {
|
|||||||
val apiElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>
|
val apiElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>
|
||||||
val runtimeElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>
|
val runtimeElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.9.20
|
||||||
|
*/
|
||||||
|
val sourcesElementsPublished: ExternalKotlinTargetConfigurationDescriptor<T>
|
||||||
|
|
||||||
val configure: ((T) -> Unit)?
|
val configure: ((T) -> Unit)?
|
||||||
val configureIdeImport: (IdeMultiplatformImport.() -> Unit)?
|
val configureIdeImport: (IdeMultiplatformImport.() -> Unit)?
|
||||||
}
|
}
|
||||||
@@ -91,6 +96,12 @@ class ExternalKotlinTargetDescriptorBuilder<T : DecoratedExternalKotlinTarget> i
|
|||||||
val runtimeElementsPublished: ExternalKotlinTargetConfigurationDescriptorBuilder<T> =
|
val runtimeElementsPublished: ExternalKotlinTargetConfigurationDescriptorBuilder<T> =
|
||||||
ExternalKotlinTargetConfigurationDescriptorBuilder()
|
ExternalKotlinTargetConfigurationDescriptorBuilder()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.9.20
|
||||||
|
*/
|
||||||
|
val sourcesElementsPublished: ExternalKotlinTargetConfigurationDescriptorBuilder<T> =
|
||||||
|
ExternalKotlinTargetConfigurationDescriptorBuilder()
|
||||||
|
|
||||||
private var configure: ((T) -> Unit)? = null
|
private var configure: ((T) -> Unit)? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,6 +139,7 @@ class ExternalKotlinTargetDescriptorBuilder<T : DecoratedExternalKotlinTarget> i
|
|||||||
sourcesElements = sourcesElements.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
|
||||||
)
|
)
|
||||||
@@ -142,6 +154,7 @@ private data class ExternalKotlinTargetDescriptorImpl<T : DecoratedExternalKotli
|
|||||||
override val sourcesElements: 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>
|
||||||
|
|||||||
+2
-1
@@ -32,6 +32,7 @@ internal class ExternalKotlinTargetImpl internal constructor(
|
|||||||
val sourcesElementsConfiguration: 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 {
|
||||||
@@ -78,7 +79,7 @@ internal class ExternalKotlinTargetImpl internal constructor(
|
|||||||
@InternalKotlinGradlePluginApi
|
@InternalKotlinGradlePluginApi
|
||||||
override val kotlinComponents: Set<KotlinTargetComponent> = setOf(kotlinTargetComponent)
|
override val kotlinComponents: Set<KotlinTargetComponent> = setOf(kotlinTargetComponent)
|
||||||
|
|
||||||
override val components: Set<SoftwareComponent> by lazy {
|
override val components: Set<ExternalKotlinTargetSoftwareComponent> by lazy {
|
||||||
logger.debug("Creating SoftwareComponent")
|
logger.debug("Creating SoftwareComponent")
|
||||||
setOf(ExternalKotlinTargetSoftwareComponent(this))
|
setOf(ExternalKotlinTargetSoftwareComponent(this))
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -31,6 +31,10 @@ internal fun ExternalKotlinTargetSoftwareComponent(
|
|||||||
details.mapToMavenScope("runtime")
|
details.mapToMavenScope("runtime")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (target.isSourcesPublishable) {
|
||||||
|
adhocSoftwareComponent.addVariantsFromConfiguration(target.sourcesElementsPublishedConfiguration) { _ -> }
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(UnsafeApi::class)
|
@OptIn(UnsafeApi::class)
|
||||||
return ExternalKotlinTargetSoftwareComponent(
|
return ExternalKotlinTargetSoftwareComponent(
|
||||||
target.project.multiplatformExtension,
|
target.project.multiplatformExtension,
|
||||||
@@ -42,7 +46,7 @@ internal fun ExternalKotlinTargetSoftwareComponent(
|
|||||||
internal class ExternalKotlinTargetSoftwareComponent @UnsafeApi constructor(
|
internal class ExternalKotlinTargetSoftwareComponent @UnsafeApi constructor(
|
||||||
private val multiplatformExtension: KotlinMultiplatformExtension,
|
private val multiplatformExtension: KotlinMultiplatformExtension,
|
||||||
private val adhocSoftwareComponent: SoftwareComponentInternal,
|
private val adhocSoftwareComponent: SoftwareComponentInternal,
|
||||||
private val kotlinTargetComponent: ExternalKotlinTargetComponent
|
private val kotlinTargetComponent: ExternalKotlinTargetComponent,
|
||||||
) : ComponentWithCoordinates, ComponentWithVariants, SoftwareComponentInternal {
|
) : ComponentWithCoordinates, ComponentWithVariants, SoftwareComponentInternal {
|
||||||
override fun getName(): String = adhocSoftwareComponent.name
|
override fun getName(): String = adhocSoftwareComponent.name
|
||||||
override fun getUsages(): Set<UsageContext> = adhocSoftwareComponent.usages
|
override fun getUsages(): Set<UsageContext> = adhocSoftwareComponent.usages
|
||||||
|
|||||||
+11
-3
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.gradle.utils.named
|
|||||||
*/
|
*/
|
||||||
@ExternalKotlinTargetApi
|
@ExternalKotlinTargetApi
|
||||||
fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExternalKotlinTarget(
|
fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExternalKotlinTarget(
|
||||||
descriptor: ExternalKotlinTargetDescriptor<T>
|
descriptor: ExternalKotlinTargetDescriptor<T>,
|
||||||
): T {
|
): T {
|
||||||
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"))
|
||||||
@@ -44,6 +44,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)
|
||||||
)
|
)
|
||||||
@@ -62,6 +65,7 @@ fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExter
|
|||||||
sourcesElementsConfiguration = sourcesElementsConfiguration,
|
sourcesElementsConfiguration = sourcesElementsConfiguration,
|
||||||
apiElementsPublishedConfiguration = apiElementsPublishedConfiguration,
|
apiElementsPublishedConfiguration = apiElementsPublishedConfiguration,
|
||||||
runtimeElementsPublishedConfiguration = runtimeElementsPublishedConfiguration,
|
runtimeElementsPublishedConfiguration = runtimeElementsPublishedConfiguration,
|
||||||
|
sourcesElementsPublishedConfiguration = sourcesElementsPublishedConfiguration,
|
||||||
kotlinTargetComponent = kotlinTargetComponent,
|
kotlinTargetComponent = kotlinTargetComponent,
|
||||||
artifactsTaskLocator = artifactsTaskLocator
|
artifactsTaskLocator = artifactsTaskLocator
|
||||||
)
|
)
|
||||||
@@ -71,6 +75,7 @@ fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExter
|
|||||||
target.setupRuntimeElements(runtimeElementsConfiguration)
|
target.setupRuntimeElements(runtimeElementsConfiguration)
|
||||||
target.setupRuntimeElements(runtimeElementsPublishedConfiguration)
|
target.setupRuntimeElements(runtimeElementsPublishedConfiguration)
|
||||||
target.setupSourcesElements(sourcesElementsConfiguration)
|
target.setupSourcesElements(sourcesElementsConfiguration)
|
||||||
|
target.setupSourcesElements(sourcesElementsPublishedConfiguration)
|
||||||
apiElementsConfiguration.markConsumable()
|
apiElementsConfiguration.markConsumable()
|
||||||
runtimeElementsConfiguration.markConsumable()
|
runtimeElementsConfiguration.markConsumable()
|
||||||
sourcesElementsConfiguration.markConsumable()
|
sourcesElementsConfiguration.markConsumable()
|
||||||
@@ -80,6 +85,8 @@ fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExter
|
|||||||
apiElementsPublishedConfiguration.isCanBeResolved = false
|
apiElementsPublishedConfiguration.isCanBeResolved = false
|
||||||
runtimeElementsPublishedConfiguration.isCanBeResolved = false
|
runtimeElementsPublishedConfiguration.isCanBeResolved = false
|
||||||
runtimeElementsPublishedConfiguration.isCanBeConsumed = false
|
runtimeElementsPublishedConfiguration.isCanBeConsumed = false
|
||||||
|
sourcesElementsPublishedConfiguration.isCanBeConsumed = false
|
||||||
|
sourcesElementsPublishedConfiguration.isCanBeResolved = false
|
||||||
|
|
||||||
val decorated = descriptor.targetFactory.create(DecoratedExternalKotlinTarget.Delegate(target))
|
val decorated = descriptor.targetFactory.create(DecoratedExternalKotlinTarget.Delegate(target))
|
||||||
target.onCreated()
|
target.onCreated()
|
||||||
@@ -90,6 +97,7 @@ fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExter
|
|||||||
descriptor.sourcesElements.configure?.invoke(decorated, sourcesElementsConfiguration)
|
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)
|
||||||
@@ -102,7 +110,7 @@ fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExter
|
|||||||
*/
|
*/
|
||||||
@ExternalKotlinTargetApi
|
@ExternalKotlinTargetApi
|
||||||
fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExternalKotlinTarget(
|
fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExternalKotlinTarget(
|
||||||
descriptor: ExternalKotlinTargetDescriptorBuilder<T>.() -> Unit
|
descriptor: ExternalKotlinTargetDescriptorBuilder<T>.() -> Unit,
|
||||||
): T {
|
): T {
|
||||||
return createExternalKotlinTarget(ExternalKotlinTargetDescriptor(descriptor))
|
return createExternalKotlinTarget(ExternalKotlinTargetDescriptor(descriptor))
|
||||||
}
|
}
|
||||||
@@ -121,4 +129,4 @@ private fun ExternalKotlinTargetImpl.setupRuntimeElements(configuration: Configu
|
|||||||
|
|
||||||
private fun ExternalKotlinTargetImpl.setupSourcesElements(configuration: Configuration) {
|
private fun ExternalKotlinTargetImpl.setupSourcesElements(configuration: Configuration) {
|
||||||
configuration.configureSourcesPublicationAttributes(this)
|
configuration.configureSourcesPublicationAttributes(this)
|
||||||
}
|
}
|
||||||
|
|||||||
+80
-3
@@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.unitTests
|
package org.jetbrains.kotlin.gradle.unitTests
|
||||||
|
|
||||||
|
import org.gradle.api.attributes.Attribute
|
||||||
|
import org.gradle.api.attributes.Category
|
||||||
|
import org.gradle.api.attributes.DocsType
|
||||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle
|
||||||
@@ -20,9 +23,8 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.external.ExternalKotlinTargetDescr
|
|||||||
import org.jetbrains.kotlin.gradle.util.buildProjectWithMPP
|
import org.jetbrains.kotlin.gradle.util.buildProjectWithMPP
|
||||||
import org.jetbrains.kotlin.gradle.util.runLifecycleAwareTest
|
import org.jetbrains.kotlin.gradle.util.runLifecycleAwareTest
|
||||||
import org.jetbrains.kotlin.gradle.utils.property
|
import org.jetbrains.kotlin.gradle.utils.property
|
||||||
import kotlin.test.Test
|
import org.jetbrains.kotlin.gradle.utils.toMap
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.*
|
||||||
import kotlin.test.assertNull
|
|
||||||
|
|
||||||
class ExternalKotlinTargetApiTests {
|
class ExternalKotlinTargetApiTests {
|
||||||
|
|
||||||
@@ -89,4 +91,79 @@ class ExternalKotlinTargetApiTests {
|
|||||||
assertEquals(KotlinSourceSetTree.main, KotlinSourceSetTree.orNull(mainCompilation))
|
assertEquals(KotlinSourceSetTree.main, KotlinSourceSetTree.orNull(mainCompilation))
|
||||||
assertNull(KotlinSourceSetTree.orNull(auxCompilation))
|
assertNull(KotlinSourceSetTree.orNull(auxCompilation))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test - sourcesElements - default configuration`() = buildProjectWithMPP().runLifecycleAwareTest {
|
||||||
|
val target = kotlin.createExternalKotlinTarget<FakeTarget> { defaults() }
|
||||||
|
|
||||||
|
assertNotEquals(target.sourcesElementsConfiguration, target.sourcesElementsPublishedConfiguration)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
target.sourcesElementsConfigurationName,
|
||||||
|
target.sourcesElementsConfiguration.name
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
target.sourcesElementsConfiguration.attributes.toMap(),
|
||||||
|
target.sourcesElementsPublishedConfiguration.attributes.toMap(),
|
||||||
|
"Expected sourcesElements and sourcesElementsPublished to contain the same attributes"
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
KotlinPlatformType.jvm, target.sourcesElementsPublishedConfiguration.attributes.getAttribute(KotlinPlatformType.attribute),
|
||||||
|
"Expected KotlinPlatformType attribute to be present"
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
Category.DOCUMENTATION, target.sourcesElementsPublishedConfiguration.attributes.getAttribute(Category.CATEGORY_ATTRIBUTE)?.name,
|
||||||
|
"Expected 'Category.DOCUMENTATION' as category attribute"
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
DocsType.SOURCES, target.sourcesElementsPublishedConfiguration.attributes.getAttribute(DocsType.DOCS_TYPE_ATTRIBUTE)?.name,
|
||||||
|
"Expected 'DocsType.SOURCES' attribute"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test - sourcesElements - configure`() = buildProjectWithMPP().runLifecycleAwareTest {
|
||||||
|
val testAttribute = Attribute.of("for.test", String::class.java)
|
||||||
|
|
||||||
|
val target = kotlin.createExternalKotlinTarget<FakeTarget> {
|
||||||
|
defaults()
|
||||||
|
sourcesElements.configure { target, configuration ->
|
||||||
|
assertEquals(target.sourcesElementsConfiguration, configuration)
|
||||||
|
configuration.attributes.attribute(testAttribute, "sourcesElements")
|
||||||
|
}
|
||||||
|
|
||||||
|
sourcesElementsPublished.configure { target, configuration ->
|
||||||
|
assertEquals(target.sourcesElementsPublishedConfiguration, configuration)
|
||||||
|
configuration.attributes.attribute(testAttribute, "sourcesElements-published")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check traces left before */
|
||||||
|
assertEquals("sourcesElements", target.sourcesElementsConfiguration.attributes.getAttribute(testAttribute))
|
||||||
|
assertEquals("sourcesElements-published", target.sourcesElementsPublishedConfiguration.attributes.getAttribute(testAttribute))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test - sourcesElements - publication`() = buildProjectWithMPP().runLifecycleAwareTest {
|
||||||
|
val target = kotlin.createExternalKotlinTarget<FakeTarget> { defaults() }
|
||||||
|
val component = target.delegate.components.singleOrNull() ?: fail("Expected single 'component' for external target")
|
||||||
|
|
||||||
|
component.usages.find { it.name == target.sourcesElementsPublishedConfiguration.name }
|
||||||
|
?: fail("Missing sourcesElements usage")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test - sourcesElements - publication - withSourcesJar set to false`() = buildProjectWithMPP().runLifecycleAwareTest {
|
||||||
|
val target = kotlin.createExternalKotlinTarget<FakeTarget> { defaults() }
|
||||||
|
target.withSourcesJar(false)
|
||||||
|
val component = target.delegate.components.singleOrNull() ?: fail("Expected single 'component' for external target")
|
||||||
|
val sourcesUsage = component.usages.find { it.name.contains("sources", true) }
|
||||||
|
if (sourcesUsage != null) {
|
||||||
|
fail("Unexpected usage '${sourcesUsage.name} in target publication")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user