diff --git a/build.gradle.kts b/build.gradle.kts index 97fcae0b3ad..18c97181f22 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -345,6 +345,7 @@ val coreLibProjects = listOfNotNull( ":kotlin-stdlib-js", ":kotlin-stdlib-jdk7", ":kotlin-stdlib-jdk8", + ":kotlin-test", ":kotlin-test:kotlin-test-annotations-common", ":kotlin-test:kotlin-test-common", ":kotlin-test:kotlin-test-jvm", @@ -637,7 +638,10 @@ tasks { listOf("clean", "assemble", "install").forEach { taskName -> register("coreLibs${taskName.capitalize()}") { - coreLibProjects.forEach { projectName -> dependsOn("$projectName:$taskName") } + for (projectName in coreLibProjects) { + if (projectName.startsWith(":kotlin-test:") && taskName == "install") continue + dependsOn("$projectName:$taskName") + } } } diff --git a/buildSrc/src/main/kotlin/tasks.kt b/buildSrc/src/main/kotlin/tasks.kt index efce0a21d66..58b37c62099 100644 --- a/buildSrc/src/main/kotlin/tasks.kt +++ b/buildSrc/src/main/kotlin/tasks.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -51,11 +40,7 @@ fun Task.dependsOnKotlinPluginInstall() { ":kotlin-gradle-plugin-model:install", ":kotlin-reflect:install", ":kotlin-annotation-processing-gradle:install", - ":kotlin-test:kotlin-test-common:install", - ":kotlin-test:kotlin-test-annotations-common:install", - ":kotlin-test:kotlin-test-jvm:install", - ":kotlin-test:kotlin-test-js:install", - ":kotlin-test:kotlin-test-junit:install", + ":kotlin-test:install", ":kotlin-gradle-subplugin-example:install", ":kotlin-stdlib-common:install", ":kotlin-stdlib:install", diff --git a/libraries/kotlin.test/annotations-common/build.gradle b/libraries/kotlin.test/annotations-common/build.gradle index 45231065ace..56e1dd87ed6 100644 --- a/libraries/kotlin.test/annotations-common/build.gradle +++ b/libraries/kotlin.test/annotations-common/build.gradle @@ -2,8 +2,6 @@ description = 'Kotlin Test Annotations Common' apply plugin: 'kotlin-platform-common' -configurePublishing(project) - jvmTarget = "1.6" dependencies { diff --git a/libraries/kotlin.test/build.gradle.kts b/libraries/kotlin.test/build.gradle.kts new file mode 100644 index 00000000000..253f916d798 --- /dev/null +++ b/libraries/kotlin.test/build.gradle.kts @@ -0,0 +1,289 @@ +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType + +plugins { + `kotlin-multiplatform` apply false + base + `maven-publish` +} + +open class ComponentsFactoryAccess +@javax.inject.Inject +constructor(val factory: SoftwareComponentFactory) + +val componentFactory = objects.newInstance().factory + + +val jvmApi by configurations.creating { + isCanBeConsumed = true + isCanBeResolved = false + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named("java-api")) + attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm) + } +} + +val jvmRuntime by configurations.creating { + isCanBeConsumed = true + isCanBeResolved = false + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named("java-runtime")) + attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm) + } + extendsFrom(jvmApi) +} + +val jsApiVariant by configurations.creating { + isCanBeConsumed = true + isCanBeResolved = false + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named("kotlin-api")) + attribute(KotlinPlatformType.attribute, KotlinPlatformType.js) + } +} +val jsRuntimeVariant by configurations.creating { + isCanBeConsumed = true + isCanBeResolved = false + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named("kotlin-runtime")) + attribute(KotlinPlatformType.attribute, KotlinPlatformType.js) + } + extendsFrom(jsApiVariant) +} + +val nativeApiVariant by configurations.creating { + isCanBeConsumed = true + isCanBeResolved = false + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named("kotlin-api")) + attribute(KotlinPlatformType.attribute, KotlinPlatformType.native) + } +} + +val commonVariant by configurations.creating { + isCanBeConsumed = true + isCanBeResolved = false + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named("kotlin-api")) + attribute(KotlinPlatformType.attribute, KotlinPlatformType.common) + } +} + +dependencies { + jvmApi(project(":kotlin-stdlib")) + jsApiVariant("$group:kotlin-test-js:$version") + commonVariant("$group:kotlin-test-common:$version") + commonVariant("$group:kotlin-test-annotations-common:$version") +} + +artifacts { + val jvmJar = tasks.getByPath(":kotlin-test:kotlin-test-jvm:jar") + add(jvmApi.name, jvmJar) + add(jvmRuntime.name, jvmJar) +} + +val kotlinTestCommonSourcesJar = tasks.getByPath(":kotlin-test:kotlin-test-common:sourcesJar") as Jar +val kotlinTestJvmSourcesJar = tasks.getByPath(":kotlin-test:kotlin-test-jvm:sourcesJar") as Jar + +val combinedSourcesJar by tasks.registering(Jar::class) { + dependsOn(kotlinTestCommonSourcesJar, kotlinTestJvmSourcesJar) + archiveClassifier.set("sources") + into("common") { + from(zipTree(kotlinTestCommonSourcesJar.archiveFile)) { + exclude("META-INF/**") + } + } + into("jvm") { + from(zipTree(kotlinTestJvmSourcesJar.archiveFile)) { + exclude("META-INF/**") + } + } +} + + +val rootComponent = componentFactory.adhoc("root").apply { + addVariantsFromConfiguration(jvmApi) { + mapToMavenScope("compile") + } + addVariantsFromConfiguration(jvmRuntime) { + mapToMavenScope("runtime") + } + addVariantsFromConfiguration(jsApiVariant) { mapToOptional() } + addVariantsFromConfiguration(jsRuntimeVariant) { mapToOptional() } + addVariantsFromConfiguration(nativeApiVariant) { mapToOptional() } + addVariantsFromConfiguration(commonVariant) { mapToOptional() } +} + + +val baseCapability = "$group:kotlin-test-framework:$version" +val implCapability = "$group:kotlin-test-framework-impl:$version" + +val jvmTestFrameworks = listOf("junit", "junit5", "testng") + +jvmTestFrameworks.forEach { framework -> + val (apiVariant, runtimeVariant) = listOf("api", "runtime").map { usage -> + configurations.create("${framework}${usage.capitalize()}Variant") { + isCanBeConsumed = true + isCanBeResolved = false + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named("java-$usage")) + attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm) + } + outgoing.capability(baseCapability) // C0 + outgoing.capability("$group:kotlin-test-framework-$framework:$version") // C0 + } + } + runtimeVariant.extendsFrom(apiVariant) + dependencies { + apiVariant("$group:kotlin-test-$framework:$version") + } + rootComponent.addVariantsFromConfiguration(apiVariant) { mapToOptional() } + rootComponent.addVariantsFromConfiguration(runtimeVariant) { mapToOptional() } + + val (apiElements, runtimeElements) = listOf("api", "runtime").map { usage -> + configurations.create("${framework}${usage.capitalize()}") { + isCanBeConsumed = true + isCanBeResolved = false + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named("java-$usage")) + } + outgoing.capability(implCapability) // CC + outgoing.capability("$group:kotlin-test-$framework:$version") // CC + } + } + runtimeElements.extendsFrom(apiElements) + dependencies { + apiElements("$group:kotlin-test:$version") + when(framework) { + "junit" -> { + apiElements("junit:junit:4.12") + } + "junit5" -> { + apiElements("org.junit.jupiter:junit-jupiter-api:5.0.0") + } + "testng" -> { + apiElements("org.testng:testng:6.13.1") + } + } + } + + artifacts { + val jar = tasks.getByPath(":kotlin-test:kotlin-test-$framework:jar") + add(apiElements.name, jar) + add(runtimeElements.name, jar) + } + + componentFactory.adhoc(framework).apply { + addVariantsFromConfiguration(apiElements) { + mapToMavenScope("compile") + } + addVariantsFromConfiguration(runtimeElements) { + mapToMavenScope("runtime") + } + }.let { components.add(it) } +} + +val (jsApi, jsRuntime) = listOf("api", "runtime").map { usage -> + configurations.create("js${usage.capitalize()}") { + isCanBeConsumed = true + isCanBeResolved = false + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named("kotlin-$usage")) + attribute(KotlinPlatformType.attribute, KotlinPlatformType.js) + } + } +} +jsRuntime.extendsFrom(jsApi) + +dependencies { + jsApi(project(":kotlin-stdlib-js")) +} + +artifacts { + val jsJar = tasks.getByPath(":kotlin-test:kotlin-test-js:libraryJarWithIr") + add(jsApi.name, jsJar) + add(jsRuntime.name, jsJar) +} + +val jsComponent = componentFactory.adhoc("js").apply { + addVariantsFromConfiguration(jsApi) { + mapToMavenScope("compile") + } + addVariantsFromConfiguration(jsRuntime) { + mapToMavenScope("runtime") + } +} + +val commonMetadata by configurations.creating { + isCanBeConsumed = true + isCanBeResolved = false + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named("kotlin-api")) + attribute(KotlinPlatformType.attribute, KotlinPlatformType.common) + } +} +val annotationsMetadata by configurations.creating { + isCanBeConsumed = true + isCanBeResolved = false + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named("kotlin-api")) + attribute(KotlinPlatformType.attribute, KotlinPlatformType.common) + } +} +dependencies { + commonMetadata(project(":kotlin-stdlib-common")) + annotationsMetadata(project(":kotlin-stdlib-common")) +} +artifacts { + add(commonMetadata.name, tasks.getByPath(":kotlin-test:kotlin-test-common:jar")) + add(annotationsMetadata.name, tasks.getByPath(":kotlin-test:kotlin-test-annotations-common:jar")) +} +val commonMetadataComponent = componentFactory.adhoc("common").apply { + addVariantsFromConfiguration(commonMetadata) { + mapToMavenScope("compile") + } +} +val annotationsMetadataComponent = componentFactory.adhoc("annotations-common").apply { + addVariantsFromConfiguration(annotationsMetadata) { + mapToMavenScope("compile") + } +} + + + +publishing { + publications { + create("main", MavenPublication::class) { + from(rootComponent) + artifact(combinedSourcesJar) + // TODO: Remove all optional dependencies from root pom + } + jvmTestFrameworks.forEach { framework -> + create(framework, MavenPublication::class) { + artifactId = "kotlin-test-$framework" + from(components[framework]) + artifact(tasks.getByPath(":kotlin-test:kotlin-test-$framework:sourcesJar") as Jar) + } + } + create("js", MavenPublication::class) { + artifactId = "kotlin-test-js" + from(jsComponent) + artifact(tasks.getByPath(":kotlin-test:kotlin-test-js:sourcesJar") as Jar) + } + create("common", MavenPublication::class) { + artifactId = "kotlin-test-common" + from(commonMetadataComponent) + artifact(tasks.getByPath(":kotlin-test:kotlin-test-common:sourcesJar") as Jar) + } + create("annotationsCommon", MavenPublication::class) { + artifactId = "kotlin-test-annotations-common" + from(annotationsMetadataComponent) + artifact(tasks.getByPath(":kotlin-test:kotlin-test-annotations-common:sourcesJar") as Jar) + } + } +} + +tasks { + val install by creating { + dependsOn(publishToMavenLocal) + } +} \ No newline at end of file diff --git a/libraries/kotlin.test/common/build.gradle b/libraries/kotlin.test/common/build.gradle index 730d97d99a9..cf0b36a35f0 100644 --- a/libraries/kotlin.test/common/build.gradle +++ b/libraries/kotlin.test/common/build.gradle @@ -2,8 +2,6 @@ description = 'Kotlin Test Common' apply plugin: 'kotlin-platform-common' -configurePublishing(project) - jvmTarget = "1.6" dependencies { diff --git a/libraries/kotlin.test/js/build.gradle b/libraries/kotlin.test/js/build.gradle index 50627f8fff5..9c194bc89c1 100644 --- a/libraries/kotlin.test/js/build.gradle +++ b/libraries/kotlin.test/js/build.gradle @@ -2,8 +2,6 @@ description = 'Kotlin Test for JS' apply plugin: 'kotlin-platform-js' -configurePublishing(project) - configurations { distJs distLibrary @@ -76,7 +74,6 @@ task sourcesJar(type: Jar, dependsOn: classes) { artifacts { runtime libraryJarWithIr archives libraryJarWithIr - publishedRuntime libraryJarWithIr distLibrary libraryJarWithIr archives sourcesJar distJs(file(compileKotlin2Js.kotlinOptions.outputFile)) { diff --git a/libraries/kotlin.test/junit/build.gradle b/libraries/kotlin.test/junit/build.gradle index 30c5736ef14..809436c2aac 100644 --- a/libraries/kotlin.test/junit/build.gradle +++ b/libraries/kotlin.test/junit/build.gradle @@ -3,7 +3,6 @@ description = 'Kotlin Test JUnit' apply plugin: 'kotlin-platform-jvm' configureJvm6Project(project) -configurePublishing(project) def includeJava9 = BuildPropertiesExtKt.getIncludeJava9(project.kotlinBuildProperties) diff --git a/libraries/kotlin.test/junit5/build.gradle b/libraries/kotlin.test/junit5/build.gradle index 51526ca91e4..411b48e69fc 100644 --- a/libraries/kotlin.test/junit5/build.gradle +++ b/libraries/kotlin.test/junit5/build.gradle @@ -3,7 +3,6 @@ description = 'Kotlin Test JUnit 5' apply plugin: 'kotlin-platform-jvm' configureJvm6Project(project) -configurePublishing(project) ext.javaHome = JDK_18 ext.jvmTarget = "1.8" diff --git a/libraries/kotlin.test/jvm/build.gradle b/libraries/kotlin.test/jvm/build.gradle index 651c29bb822..5dd30c3d69e 100644 --- a/libraries/kotlin.test/jvm/build.gradle +++ b/libraries/kotlin.test/jvm/build.gradle @@ -6,9 +6,6 @@ archivesBaseName = 'kotlin-test' configureJvm6Project(project) -configurePublishing(project) { - artifactId = archivesBaseName -} def includeJava9 = BuildPropertiesExtKt.getIncludeJava9(project.kotlinBuildProperties) diff --git a/libraries/kotlin.test/testng/build.gradle b/libraries/kotlin.test/testng/build.gradle index 968b937bef9..4f54d75a130 100644 --- a/libraries/kotlin.test/testng/build.gradle +++ b/libraries/kotlin.test/testng/build.gradle @@ -3,7 +3,6 @@ description = 'Kotlin Test TestNG' apply plugin: 'kotlin-platform-jvm' configureJvm6Project(project) -configurePublishing(project) ext.javaHome = JDK_17 def includeJava9 = BuildPropertiesExtKt.getIncludeJava9(project.kotlinBuildProperties)