From 59cdcac2afb2812b042115cf9fe8a580423daf81 Mon Sep 17 00:00:00 2001 From: Jakob Havstein Eriksen Date: Mon, 27 Nov 2023 08:49:11 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A8=20Forbedringer=20i=20build-filene?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - legger til eksplisitt avhengighet til junit-platform-launcher - fordi gradle advarer om at det vil kreves i v9 - moderne måte å konfigurere tasks på: bruke named/register i stedet for withType - bytter ut manuell kopiering som bruker deprecated `buildDir` med gradle sin sync-task - erstatter separate junit-avhengigheter med aggregert junit-jupiter --- build.gradle.kts | 12 ++++----- spesialist-migrering/build.gradle.kts | 30 +++++++++++---------- spesialist-opprydding-dev/build.gradle.kts | 31 ++++++++++++---------- spesialist-selve/build.gradle.kts | 16 +++++------ 4 files changed, 46 insertions(+), 43 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 064163a9e..919b9c919 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ val junitJupiterVersion = "5.10.1" +val junitPlatformLauncherVersion = "1.9.2" val ktorVersion = "2.3.5" val jvmTargetVersion = "17" val graphqlKotlinVersion = "7.0.2" @@ -72,15 +73,12 @@ allprojects { implementation("io.ktor:ktor-server-cors:$ktorVersion") implementation("io.ktor:ktor-server-call-id:$ktorVersion") - - testImplementation("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion") - testImplementation("org.junit.jupiter:junit-jupiter-params:$junitJupiterVersion") + testRuntimeOnly("org.junit.platform:junit-platform-launcher:$junitPlatformLauncherVersion") + testImplementation("org.junit.jupiter:junit-jupiter:$junitJupiterVersion") testImplementation("io.ktor:ktor-client-mock-jvm:$ktorVersion") testImplementation("io.ktor:ktor-server-test-host:$ktorVersion") { exclude(group = "junit") } - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion") - testImplementation("io.mockk:mockk:$mockkVersion") } } @@ -90,7 +88,7 @@ subprojects { jvmToolchain(17) } tasks { - withType { + named("test") { useJUnitPlatform() testLogging { events("skipped", "failed") @@ -98,7 +96,7 @@ subprojects { exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL } } - withType() { + register("wrapper") { gradleVersion = "8.4" } } diff --git a/spesialist-migrering/build.gradle.kts b/spesialist-migrering/build.gradle.kts index 51ef1443b..5b9db18aa 100644 --- a/spesialist-migrering/build.gradle.kts +++ b/spesialist-migrering/build.gradle.kts @@ -6,24 +6,26 @@ dependencies { implementation("org.postgresql:postgresql:$postgresqlVersion") implementation("com.google.cloud.sql:postgres-socket-factory:$cloudSqlVersion") implementation(project(":spesialist-felles")) + testImplementation("org.testcontainers:postgresql:$testcontainersVersion") } -tasks.named("jar") { - archiveBaseName.set("app") +tasks { + named("jar") { + archiveBaseName.set("app") - manifest { - attributes["Main-Class"] = "no.nav.helse.migrering.AppKt" - attributes["Class-Path"] = configurations.runtimeClasspath.get().joinToString(separator = " ") { - it.name + manifest { + attributes["Main-Class"] = "no.nav.helse.migrering.AppKt" + attributes["Class-Path"] = configurations.runtimeClasspath.get().joinToString(separator = " ") { + it.name + } } } - - doLast { - configurations.runtimeClasspath.get().forEach { - val file = File("$buildDir/libs/${it.name}") - if (!file.exists()) - it.copyTo(file) - } + val copyDeps by registering(Sync::class) { + from(configurations.runtimeClasspath) + into("build/libs") } -} \ No newline at end of file + named("assemble") { + dependsOn(copyDeps) + } +} diff --git a/spesialist-opprydding-dev/build.gradle.kts b/spesialist-opprydding-dev/build.gradle.kts index 8b03a381b..363f7a0cc 100644 --- a/spesialist-opprydding-dev/build.gradle.kts +++ b/spesialist-opprydding-dev/build.gradle.kts @@ -1,6 +1,8 @@ val testcontainersVersion = "1.19.1" val cloudSqlVersion = "1.14.1" val postgresqlVersion = "42.6.0" +val junitJupiterVersion = "5.10.1" +val junitPlatformLauncherVersion = "1.9.2" val mainClass = "no.nav.helse.opprydding.AppKt" @@ -19,21 +21,22 @@ dependencies { } } -tasks.named("jar") { - archiveBaseName.set("app") +tasks { + named("jar") { + archiveBaseName.set("app") - manifest { - attributes["Main-Class"] = mainClass - attributes["Class-Path"] = configurations.runtimeClasspath.get().joinToString(separator = " ") { - it.name + manifest { + attributes["Main-Class"] = mainClass + attributes["Class-Path"] = configurations.runtimeClasspath.get().joinToString(separator = " ") { + it.name + } } } - - doLast { - configurations.runtimeClasspath.get().forEach { - val file = File("$buildDir/libs/${it.name}") - if (!file.exists()) - it.copyTo(file) - } + val copyDeps by registering(Sync::class) { + from(configurations.runtimeClasspath) + into("build/libs") } -} \ No newline at end of file + named("assemble") { + dependsOn(copyDeps) + } +} diff --git a/spesialist-selve/build.gradle.kts b/spesialist-selve/build.gradle.kts index 8b69c9323..7513f4945 100644 --- a/spesialist-selve/build.gradle.kts +++ b/spesialist-selve/build.gradle.kts @@ -12,6 +12,7 @@ dependencies { implementation(project(":spesialist-felles")) implementation(project(":spesialist-api")) implementation(project(":spesialist-modell")) + testImplementation("org.testcontainers:postgresql:$testcontainersVersion") } @@ -25,13 +26,12 @@ tasks { it.name } } - - doLast { - configurations.runtimeClasspath.get().forEach { - val file = File("$buildDir/deps/${it.name}") - if (!file.exists()) - it.copyTo(file) - } - } + } + val copyDeps by registering(Sync::class) { + from(configurations.runtimeClasspath) + into("build/deps") + } + named("assemble") { + dependsOn(copyDeps) } }