Files
com_r35157_nenjim-hubd-tests/build.gradle.kts

128 lines
3.8 KiB
Kotlin
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
plugins {
id("java")
id("maven-publish")
}
group = "com.r35157.nenjim"
version = project.findProperty("version") ?: "UNSET"
if (version == "UNSET" && gradle.startParameter.taskNames.any { it.startsWith("publish") }) {
throw GradleException("You must set -Pversion=... (use publish.sh / publishCICD.sh)")
}
repositories {
mavenLocal()
maven {
name = "Artifacts"
url = uri("/mnt/artifacts/java")
// Failsafe for Android variant-aware deps + klassiske Maven-artefakter:
metadataSources {
gradleMetadata() // bevar .module for Android/AAR varianter
mavenPom()
artifact()
}
}
mavenCentral()
}
dependencies {
// The test classes are compiled with these:
implementation("com.r35157.nenjim:hubd-api:0.0.0")
implementation("com.r35157.nenjim:hubd-impl-ref:0.0.0")
implementation("org.jetbrains:annotations:26.0.1")
// The JUnit platform will not be included in the JAR file but are needed for running the tests:
testImplementation(platform("org.junit:junit-bom:5.11.4"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
java {
toolchain { languageVersion.set(JavaLanguageVersion.of(24)) }
}
tasks.withType<JavaCompile> {
options.release.set(24)
}
tasks.test {
useJUnitPlatform()
// Standard JUnit logning behold defaults
}
/** Kun tests-jar slå standard :jar fra for at undgå filnavnskonflikt */
tasks.jar {
enabled = false
}
val testSummary by tasks.registering(Test::class) {
description = "Runs tests and prints only a compact summary"
group = "verification"
// ---- wire inputs/classpath ----
testClassesDirs = sourceSets.test.get().output.classesDirs
classpath = sourceSets.test.get().runtimeClasspath
dependsOn(tasks.named("testClasses")) // ensures tests are compiled
useJUnitPlatform()
// Disable normal per-test logging
testLogging {
events() // Ingen events
showExceptions = false
showStackTraces = false
showCauses = false
}
// Our own custom compact status report
addTestListener(object : TestListener {
override fun beforeSuite(suite: TestDescriptor) {}
override fun beforeTest(testDescriptor: TestDescriptor) {}
override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {}
override fun afterSuite(suite: TestDescriptor, result: TestResult) {
// Only for the whole test suite (top level)
if (suite.parent == null) {
val total = result.testCount
val failed = result.failedTestCount
val skipped = result.skippedTestCount
val passed = total - failed - skipped
// Choose icon - based on status
val status = when {
failed > 0 -> "\uD83D\uDD34" // Red
skipped > 0 -> "\uD83D\uDFE1" // Yellow
else -> "\uD83D\uDFE2" // Green
}
println("\n$status $passed passed, $failed failed, $skipped skipped (Total: $total tests)")
}
}
})
}
val testJar by tasks.registering(Jar::class) {
from(sourceSets.test.get().output)
archiveBaseName.set("hubd-tests")
archiveVersion.set(version.toString())
description = "Assembles a jar archive containing the test classes."
group = "build"
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
artifactId = "hubd-tests"
artifact(testJar.get()) // Use test-jar as the artifact
}
}
repositories {
maven {
name = "Artifacts"
url = uri("/mnt/artifacts/java")
}
}
}