[kotlin-test] Additional framework jars and outgoing configurations KT-61969
This commit is contained in:
committed by
Space Team
parent
008a961913
commit
2db2b18910
@@ -1,5 +1,8 @@
|
|||||||
@file:Suppress("UNUSED_VARIABLE")
|
@file:Suppress("UNUSED_VARIABLE")
|
||||||
|
|
||||||
|
import org.gradle.jvm.tasks.Jar
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
|
||||||
|
|
||||||
|
|
||||||
@@ -197,3 +200,142 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
val allMetadataJar by existing(Jar::class) {
|
||||||
|
archiveClassifier = "all"
|
||||||
|
}
|
||||||
|
val jvmJar by existing(Jar::class) {
|
||||||
|
archiveAppendix = null
|
||||||
|
from(project.sourceSets["jvmJava9"].output)
|
||||||
|
manifestAttributes(manifest, "Test", multiRelease = true)
|
||||||
|
}
|
||||||
|
val jvmSourcesJar by existing(Jar::class) {
|
||||||
|
archiveAppendix = null
|
||||||
|
kotlin.sourceSets["annotationsCommonMain"].let { sourceSet ->
|
||||||
|
into(sourceSet.name) {
|
||||||
|
from(sourceSet.kotlin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val jvmJarTasks = jvmTestFrameworks.map { framework ->
|
||||||
|
named("jvm${framework}Jar", Jar::class) {
|
||||||
|
archiveBaseName = base.archivesName
|
||||||
|
archiveAppendix = framework.lowercase()
|
||||||
|
from(project.sourceSets["jvm${framework}Java9"].output)
|
||||||
|
manifestAttributes(manifest, "Test", multiRelease = true)
|
||||||
|
manifest.attributes("Implementation-Title" to "${archiveBaseName.get()}-${archiveAppendix.get()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val jvmSourcesJarTasks = jvmTestFrameworks.map { framework ->
|
||||||
|
register("jvm${framework}SourcesJar", Jar::class) {
|
||||||
|
archiveAppendix = framework.lowercase()
|
||||||
|
archiveClassifier = "sources"
|
||||||
|
kotlin.jvm().compilations[framework.name].allKotlinSourceSets.forEach {
|
||||||
|
from(it.kotlin.sourceDirectories) { into(it.name) }
|
||||||
|
from(it.resources.sourceDirectories) { into(it.name) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val jsJar by existing(Jar::class) {
|
||||||
|
manifestAttributes(manifest, "Test")
|
||||||
|
manifest.attributes("Implementation-Title" to "${archiveBaseName.get()}-${archiveAppendix.get()}")
|
||||||
|
}
|
||||||
|
val wasmJsJar by existing(Jar::class) {
|
||||||
|
manifestAttributes(manifest, "Test")
|
||||||
|
manifest.attributes("Implementation-Title" to "${archiveBaseName.get()}-${archiveAppendix.get()}")
|
||||||
|
}
|
||||||
|
val wasmWasiJar by existing(Jar::class) {
|
||||||
|
manifestAttributes(manifest, "Test")
|
||||||
|
manifest.attributes("Implementation-Title" to "${archiveBaseName.get()}-${archiveAppendix.get()}")
|
||||||
|
}
|
||||||
|
val assemble by existing {
|
||||||
|
dependsOn(jvmJarTasks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
val metadataApiElements by getting
|
||||||
|
metadataApiElements.outgoing.capability(kotlinTestCapability)
|
||||||
|
|
||||||
|
for (framework in jvmTestFrameworks) {
|
||||||
|
val frameworkCapability = "$group:kotlin-test-framework-${framework.lowercase()}:$version"
|
||||||
|
metadataApiElements.outgoing.capability(frameworkCapability)
|
||||||
|
|
||||||
|
val runtimeDeps = create("jvm${framework}RuntimeDependencies") {
|
||||||
|
isCanBeResolved = true
|
||||||
|
isCanBeConsumed = false
|
||||||
|
}
|
||||||
|
val (apiElements, runtimeElements, sourcesElements) = listOf(KotlinUsages.KOTLIN_API, KotlinUsages.KOTLIN_RUNTIME, KotlinUsages.KOTLIN_SOURCES).map { usage ->
|
||||||
|
val name = "jvm$framework${usage.substringAfter("kotlin-").replaceFirstChar { it.uppercase() }}Elements"
|
||||||
|
create(name) {
|
||||||
|
isCanBeResolved = false
|
||||||
|
isCanBeConsumed = true
|
||||||
|
outgoing.capability(baseCapability)
|
||||||
|
outgoing.capability(frameworkCapability)
|
||||||
|
attributes {
|
||||||
|
attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(TargetJvmEnvironment.STANDARD_JVM))
|
||||||
|
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements.JAR))
|
||||||
|
attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
|
||||||
|
when (usage) {
|
||||||
|
KotlinUsages.KOTLIN_SOURCES -> {
|
||||||
|
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
|
||||||
|
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
|
||||||
|
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType.SOURCES))
|
||||||
|
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
|
||||||
|
}
|
||||||
|
KotlinUsages.KOTLIN_API -> {
|
||||||
|
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_API))
|
||||||
|
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
|
||||||
|
extendsFrom(getByName("jvm${framework}Api"))
|
||||||
|
}
|
||||||
|
KotlinUsages.KOTLIN_RUNTIME -> {
|
||||||
|
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
|
||||||
|
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
|
||||||
|
runtimeDeps.extendsFrom(getByName("jvm${framework}Api"))
|
||||||
|
runtimeDeps.extendsFrom(getByName("jvm${framework}Implementation"))
|
||||||
|
runtimeDeps.extendsFrom(getByName("jvm${framework}RuntimeOnly"))
|
||||||
|
extendsFrom(runtimeDeps)
|
||||||
|
}
|
||||||
|
else -> error(usage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
apiElements(project)
|
||||||
|
runtimeDeps(project)
|
||||||
|
when (framework) {
|
||||||
|
JvmTestFramework.JUnit -> {}
|
||||||
|
JvmTestFramework.JUnit5 -> {
|
||||||
|
apiElements("org.junit.jupiter:junit-jupiter-api:5.6.3")
|
||||||
|
runtimeDeps("org.junit.jupiter:junit-jupiter-engine:5.6.3")
|
||||||
|
}
|
||||||
|
JvmTestFramework.TestNG -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
artifacts {
|
||||||
|
add(apiElements.name, tasks.named<Jar>("jvm${framework}Jar"))
|
||||||
|
add(runtimeElements.name, tasks.named<Jar>("jvm${framework}Jar"))
|
||||||
|
add(sourcesElements.name, tasks.named<Jar>("jvm${framework}SourcesJar"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (configurationName in listOf("kotlinTestCommon", "kotlinTestAnnotationsCommon")) {
|
||||||
|
val legacyConfigurationDeps = create("${configurationName}Dependencies") {
|
||||||
|
isCanBeResolved = true
|
||||||
|
isCanBeConsumed = false
|
||||||
|
}
|
||||||
|
val legacyConfiguration = create("${configurationName}Elements") {
|
||||||
|
isCanBeResolved = false
|
||||||
|
isCanBeConsumed = false
|
||||||
|
attributes {
|
||||||
|
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
|
||||||
|
}
|
||||||
|
extendsFrom(legacyConfigurationDeps)
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
legacyConfigurationDeps(project)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user