Skip to content

Commit

Permalink
🚨 Forbedringer i build-filene
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
havstein committed Nov 27, 2023
1 parent e142bd2 commit 59cdcac
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 43 deletions.
12 changes: 5 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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")
}
}
Expand All @@ -90,15 +88,15 @@ subprojects {
jvmToolchain(17)
}
tasks {
withType<Test> {
named<Test>("test") {
useJUnitPlatform()
testLogging {
events("skipped", "failed")
showStackTraces = true
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
withType<Wrapper>() {
register<Wrapper>("wrapper") {
gradleVersion = "8.4"
}
}
Expand Down
30 changes: 16 additions & 14 deletions spesialist-migrering/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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>("jar") {
archiveBaseName.set("app")
tasks {
named<Jar>("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")
}
}
named("assemble") {
dependsOn(copyDeps)
}
}
31 changes: 17 additions & 14 deletions spesialist-opprydding-dev/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -19,21 +21,22 @@ dependencies {
}
}

tasks.named<Jar>("jar") {
archiveBaseName.set("app")
tasks {
named<Jar>("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")
}
}
named("assemble") {
dependsOn(copyDeps)
}
}
16 changes: 8 additions & 8 deletions spesialist-selve/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
implementation(project(":spesialist-felles"))
implementation(project(":spesialist-api"))
implementation(project(":spesialist-modell"))

testImplementation("org.testcontainers:postgresql:$testcontainersVersion")
}

Expand All @@ -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)
}
}

0 comments on commit 59cdcac

Please sign in to comment.