From 39578b751ec621afcea4b5c680ce039f453a0445 Mon Sep 17 00:00:00 2001 From: Guillermo Mazzola Date: Sun, 3 Dec 2023 16:56:26 +0100 Subject: [PATCH] Improved test setup --- build.gradle.kts | 26 +++---------------- core/build.gradle.kts | 12 +++++++++ .../gmazzo/codeowners/CodeOwnersTest.kt | 4 +-- gradle/libs.versions.toml | 1 + plugin/build.gradle.kts | 18 ++++++++++++- .../codeowners/CodeOwnersPluginITest.kt | 3 ++- .../resources/project/build.gradle.kts | 4 +-- .../resources/project/settings.gradle.kts | 13 +++------- 8 files changed, 43 insertions(+), 38 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index fdfcb2b..84c4219 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ plugins { + base alias(libs.plugins.kotlin.jvm) apply false alias(libs.plugins.gradle.nexusPublish) `git-versioning` @@ -14,31 +15,10 @@ nexusPublishing { } allprojects { - group = "io.github.gmazzo.codeowners" - plugins.withId("java") { - - apply(plugin = "jacoco-report-aggregation") - - dependencies { - "testImplementation"(libs.kotlin.test) - "testImplementation"("org.junit.jupiter:junit-jupiter-params") - } - - tasks.withType().configureEach { - useJUnitPlatform() - workingDir(provider { temporaryDir }) - } - - tasks.withType().configureEach { - reports.xml.required.set(true) - } - - tasks.named("check") { - dependsOn(tasks.withType()) - } - + tasks.withType().configureEach { + reports.xml.required = true } } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index ec1fa6f..f580f3b 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -2,12 +2,20 @@ plugins { alias(libs.plugins.kotlin.jvm) `java-test-fixtures` `maven-central-publish` + jacoco } description = "CodeOwners Library" java.toolchain.languageVersion.set(JavaLanguageVersion.of(8)) +testing.suites.withType { + useKotlinTest(libs.versions.kotlin) + dependencies { + implementation(platform(libs.junit.bom)) + } +} + publishing.publications { create("java") { from(components["java"]) } } @@ -17,3 +25,7 @@ components.named("java") { withVariantsFromConfiguration(configurations.testFixturesApiElements.get()) { skip() } withVariantsFromConfiguration(configurations.testFixturesRuntimeElements.get()) { skip() } } + +publishing.repositories { + maven(layout.buildDirectory.dir("repo")) { name = "Local" } +} diff --git a/core/src/test/kotlin/io/github/gmazzo/codeowners/CodeOwnersTest.kt b/core/src/test/kotlin/io/github/gmazzo/codeowners/CodeOwnersTest.kt index d4e34af..ecb22ff 100644 --- a/core/src/test/kotlin/io/github/gmazzo/codeowners/CodeOwnersTest.kt +++ b/core/src/test/kotlin/io/github/gmazzo/codeowners/CodeOwnersTest.kt @@ -8,9 +8,9 @@ import foo.Foo import foo.bar.FooBar import foo.bar.impl.FooBarImpl import foo.impl.FooImpl -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test import java.lang.reflect.Proxy +import kotlin.test.Test +import kotlin.test.assertEquals class CodeOwnersTest { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7f31939..1834611 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,6 +3,7 @@ kotlin = "1.9.21" [libraries] jgit = "org.eclipse.jgit:org.eclipse.jgit:6.7.0.202309050840-r" +junit-bom = "org.junit:junit-bom:5.8.1" kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } [plugins] diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index a80ebfd..67db0ae 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -7,6 +7,7 @@ plugins { alias(libs.plugins.gradle.pluginPublish) `java-integration-tests` `maven-central-publish` + jacoco } description = "CodeOwners Gradle Plugin" @@ -29,11 +30,22 @@ dependencies { testImplementation(gradleKotlinDsl()) testRuntimeOnly(plugin(libs.plugins.kotlin.jvm)) - pluginUnderTestImplementation(projects.core) pluginUnderTestImplementation(plugin(libs.plugins.android)) pluginUnderTestImplementation(plugin(libs.plugins.kotlin.jvm)) } +testing.suites.withType { + useKotlinTest(libs.versions.kotlin) + dependencies { + implementation(platform(libs.junit.bom)) + } + targets.all { + testTask { + workingDir(provider { temporaryDir }) + } + } +} + gradlePlugin { website.set("https://github.com/gmazzo/gradle-codeowners-plugin") vcsUrl.set("https://github.com/gmazzo/gradle-codeowners-plugin") @@ -61,6 +73,10 @@ buildConfig { tasks.integrationTest { shouldRunAfter(tasks.test) + val core = projects.core.dependencyProject + dependsOn("${core.path}:publishAllPublicationsToLocalRepository") + environment("LOCAL_REPO", core.layout.buildDirectory.dir("repo").get().asFile.toRelativeString(workingDir)) + // AGP 8 requires JDK 17, and we want to be compatible with previous JDKs javaLauncher.set(javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion.of(17)) diff --git a/plugin/src/integrationTest/kotlin/io/github/gmazzo/codeowners/CodeOwnersPluginITest.kt b/plugin/src/integrationTest/kotlin/io/github/gmazzo/codeowners/CodeOwnersPluginITest.kt index c7080be..512a513 100644 --- a/plugin/src/integrationTest/kotlin/io/github/gmazzo/codeowners/CodeOwnersPluginITest.kt +++ b/plugin/src/integrationTest/kotlin/io/github/gmazzo/codeowners/CodeOwnersPluginITest.kt @@ -25,7 +25,8 @@ class CodeOwnersPluginITest { withEnvironment( mapOf( "ANDROID_HOME" to System.getenv("ANDROID_HOME"), - "pluginsClasspath" to pluginClasspath.joinToString(separator = File.pathSeparator) + "PLUGINS_CLASSPATH" to pluginClasspath.joinToString(separator = File.pathSeparator), + "LOCAL_REPO" to System.getenv("LOCAL_REPO"), ) ) } diff --git a/plugin/src/integrationTest/resources/project/build.gradle.kts b/plugin/src/integrationTest/resources/project/build.gradle.kts index 2003933..a7d229a 100644 --- a/plugin/src/integrationTest/resources/project/build.gradle.kts +++ b/plugin/src/integrationTest/resources/project/build.gradle.kts @@ -1,7 +1,7 @@ plugins { - val pluginsClasspath: String? by System.getenv().withDefault { null } + val PLUGINS_CLASSPATH: String? by System.getenv().withDefault { null } - if (pluginsClasspath == null) { + if (PLUGINS_CLASSPATH == null) { // meant to allow open this test project as a standalone project id("com.android.application") version "7.4.0" apply false kotlin("jvm") version "1.7.21" apply false diff --git a/plugin/src/integrationTest/resources/project/settings.gradle.kts b/plugin/src/integrationTest/resources/project/settings.gradle.kts index 5dd3e40..b6a8d6f 100644 --- a/plugin/src/integrationTest/resources/project/settings.gradle.kts +++ b/plugin/src/integrationTest/resources/project/settings.gradle.kts @@ -1,8 +1,9 @@ import java.io.File -val pluginsClasspath: String? by System.getenv().withDefault { null } +val PLUGINS_CLASSPATH: String? by System.getenv().withDefault { null } +val LOCAL_REPO: String? by System.getenv().withDefault { null } -if (pluginsClasspath == null) { +if (PLUGINS_CLASSPATH == null) { // meant to allow open this test project as a standalone project pluginManagement { repositories { @@ -19,13 +20,7 @@ dependencyResolutionManagement { mavenLocal() mavenCentral() google() - - // allows resolution of the local core dependency added by the plugin - pluginsClasspath?.split(File.pathSeparatorChar)?.let { paths -> - flatDir { - dir(paths.map { file(it).parentFile }) - } - } + LOCAL_REPO?.let { maven(File(it)) } } }