// SPDX-License-Identifier: MIT // © Copyright 2023-2024 Caleb Cushing. All rights reserved. import org.gradle.accessors.dm.LibrariesForLibs import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent plugins { `java-library` } val libs = the() dependencies { testImplementation(platform(libs.junit.bom)) testImplementation(libs.bundles.test) testRuntimeOnly(libs.bundles.junit.platform) } val available = tasks.register("tests available") { val java: Provider = sourceSets.test.map { it.java } doLast { if (java.get().isEmpty) throw RuntimeException("no tests found") } } tasks.withType().configureEach { useJUnitPlatform() testLogging { lifecycle { showStandardStreams = true displayGranularity = 2 exceptionFormat = TestExceptionFormat.FULL events.addAll( listOf( TestLogEvent.SKIPPED, TestLogEvent.FAILED, ), ) } } inputs.dir(rootProject.file("buildSrc/src/main")) finalizedBy(available) afterSuite( KotlinClosure2( { descriptor, result -> if (descriptor.parent == null) { logger.lifecycle("Tests run: ${result.testCount}, Failures: ${result.failedTestCount}, Skipped: ${result.skippedTestCount}") if (result.testCount == 0L) throw IllegalStateException("You cannot have 0 tests") } Unit }, ), ) }