From 7948193cf7316a4b8a0884c6ee46fc55b3701f75 Mon Sep 17 00:00:00 2001 From: Dmitry Baev Date: Wed, 31 Jul 2024 13:00:18 +0100 Subject: [PATCH] fix(allure-scalatest): cross-build for scala 2.12 and 2.13 (via #1107) --- allure-scalatest/build.gradle.kts | 115 +++++++++----------- build.gradle.kts | 16 +-- gradle/quality-configs/spotbugs/exclude.xml | 3 + 3 files changed, 63 insertions(+), 71 deletions(-) diff --git a/allure-scalatest/build.gradle.kts b/allure-scalatest/build.gradle.kts index 2aa0f8d31..039f8bb3a 100644 --- a/allure-scalatest/build.gradle.kts +++ b/allure-scalatest/build.gradle.kts @@ -2,84 +2,78 @@ import org.gradle.jvm.tasks.Jar description = "Allure ScalaTest Integration" -apply(plugin = "scala") +plugins { + scala + id("com.github.prokod.gradle-crossbuild") version "0.16.0" +} -val availableScalaVersions = listOf("2.12", "2.13") -val defaultScala212Version = "2.12.19" -val defaultScala213Version = "2.13.14" +val scala212 = "2.12" +val scala213 = "2.13" -var selectedScalaVersion = defaultScala213Version +project.base.archivesName.set("allure-scalatest") -if (hasProperty("scalaVersion")) { - val scalaVersion: String by project - selectedScalaVersion = when (scalaVersion) { - "2.12" -> defaultScala212Version - "2.13" -> defaultScala213Version - else -> scalaVersion +crossBuild { + scalaVersionsCatalog = mapOf( + scala212 to "2.12.19", + scala213 to "2.13.14" + ) + builds { + register("scala") { + scalaVersions = setOf(scala212, scala213) + } } } -val baseScalaVersion = selectedScalaVersion.substring(0, selectedScalaVersion.lastIndexOf(".")) -project.base.archivesName.set("allure-scalatest_$baseScalaVersion") - -for (sv in availableScalaVersions) { - val taskSuffix = sv.replace('.', '_') +val crossBuildScala_212Jar by tasks.getting +val crossBuildScala_213Jar by tasks.getting - tasks.create("jarScala_$taskSuffix", GradleBuild::class) { - startParameter = project.gradle.startParameter.newInstance() - startParameter.projectProperties["scalaVersion"] = sv - tasks = listOf("jar") - } +val scaladocJar by tasks.creating(Jar::class) { + from(tasks.getByName("scaladoc")) + archiveClassifier.set("scaladoc") +} - tasks.create("testScala_$taskSuffix", GradleBuild::class) { - startParameter = project.gradle.startParameter.newInstance() - startParameter.projectProperties["scalaVersion"] = sv - tasks = listOf("test") +tasks.withType().configureEach { + val predicate = provider { + publication != publishing.publications["maven"] } - - tasks.create("sourceJarScala_$taskSuffix", GradleBuild::class) { - startParameter = project.gradle.startParameter.newInstance() - startParameter.projectProperties["scalaVersion"] = sv - tasks = listOf("sourceJar") + onlyIf("disable default maven publication") { + predicate.get() } +} - tasks.create("scaladocJarScala_$taskSuffix", GradleBuild::class) { - startParameter = project.gradle.startParameter.newInstance() - startParameter.projectProperties["scalaVersion"] = sv - tasks = listOf("scaladocJar") +tasks.withType().configureEach { + val predicate = provider { + publication != publishing.publications["maven"] } - - tasks.create("installScala_$taskSuffix", GradleBuild::class) { - startParameter = project.gradle.startParameter.newInstance() - startParameter.projectProperties["scalaVersion"] = sv - tasks = listOf("install") + onlyIf("disable default maven publication") { + predicate.get() } } -val jarAll by tasks.creating { - dependsOn(availableScalaVersions.map { "jarScala_${it.replace('.', '_')}" }) -} - -val testAll by tasks.creating { - dependsOn(availableScalaVersions.map { "testScala_${it.replace('.', '_')}" }) -} - -val sourceJarAll by tasks.creating { - dependsOn(availableScalaVersions.map { "sourceJarScala_${it.replace('.', '_')}" }) -} - -val scaladocJarAll by tasks.creating { - dependsOn(availableScalaVersions.map { "scaladocJarScala_${it.replace('.', '_')}" }) +publishing { + publications { + create("crossBuildScala_212") { + from(components["crossBuildScala_212"]) + artifact(scaladocJar) + artifact(tasks.sourcesJar) + } + create("crossBuildScala_213") { + from(components["crossBuildScala_213"]) + artifact(scaladocJar) + artifact(tasks.sourcesJar) + } + } } -val installAll by tasks.creating { - dependsOn(availableScalaVersions.map { "installScala_${it.replace('.', '_')}" }) +signing { + sign(publishing.publications["crossBuildScala_212"]) + sign(publishing.publications["crossBuildScala_213"]) } dependencies { api(project(":allure-java-commons")) - implementation("org.scalatest:scalatest_$baseScalaVersion:3.2.19") - implementation("org.scala-lang.modules:scala-collection-compat_$baseScalaVersion:2.12.0") + implementation("org.scalatest:scalatest_$scala213:3.2.19") + implementation("org.scala-lang.modules:scala-collection-compat_$scala213:2.12.0") testAnnotationProcessor(project(":allure-descriptions-javadoc")) testImplementation("io.github.glytching:junit-extensions") testImplementation("org.assertj:assertj-core") @@ -92,13 +86,6 @@ dependencies { testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") } -val scaladocJar by tasks.creating(Jar::class) { - from(tasks.getByName("scaladoc")) - archiveClassifier.set("scaladoc") -} - -artifacts.add("archives", scaladocJar) - tasks.jar { manifest { attributes(mapOf( diff --git a/build.gradle.kts b/build.gradle.kts index 2fb93b6c8..ce3370c87 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -56,13 +56,7 @@ configure(subprojects) { publishing { publications { - create("maven") { - suppressAllPomMetadataWarnings() - versionMapping { - allVariants { - fromResolutionResult() - } - } + withType().configureEach { pom { name.set(project.name) description.set("Module ${project.name} of Allure Framework.") @@ -106,6 +100,14 @@ configure(subprojects) { } } } + create("maven") { + suppressAllPomMetadataWarnings() + versionMapping { + allVariants { + fromResolutionResult() + } + } + } } } diff --git a/gradle/quality-configs/spotbugs/exclude.xml b/gradle/quality-configs/spotbugs/exclude.xml index 0b8a2de89..f942c310b 100644 --- a/gradle/quality-configs/spotbugs/exclude.xml +++ b/gradle/quality-configs/spotbugs/exclude.xml @@ -6,6 +6,9 @@ + + +