Java and gradle novice here. I have a project with two subprojects: a Java application 00 and a Java library 01. I am using the JUnit 5 to test the library 01. Below is the build script that I am using. It works: if I do “gradle” in the root project dir, it does run on subproject 00 and build on subproject 01; the latter produces some test results as expected, but the output format of the test results is plain, and looks only like test foo PASSED. I want to use the JUnit Console Launcher, so that I get better output from the tests. How do I change the build script for that? Thanks.
I have tried some changes following the Junit5 project build script. However, when I do gradle, I get an error “classpath = sourceSets[“test”].runtimeClasspath … Unresolved reference: sourceSets”. Where is the name sourceSets, and what do I have to import to use it? My current build.gradle.kts is as below. Thanks.
val applicationSubprojects: List<String> = listOf("00")
fun mainTaskName(subproject: String): String =
if(subproject in applicationSubprojects) "run" else "build"
allprojects {
repositories {
jcenter()
}
task("make")
defaultTasks("make")
}
subprojects {
apply(plugin = "java")
if(project.name in applicationSubprojects) {
apply(plugin = "application")
}
dependencies {
"testImplementation"(
group = "org.junit.jupiter",
name = "junit-jupiter",
version = "5.5.0-M1"
)
"testRuntimeOnly"(
group = "org.junit.platform",
name = "junit-platform-console",
version = "1.5.0-M1"
)
}
tasks.named("make") {
dependsOn(mainTaskName(project.name))
}
tasks.named<Test>("test") {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
dependsOn("consoleLauncherTest")
}
task<JavaExec>("consoleLauncherTest") {
dependsOn("testClasses")
val reportsDir: File = file("$buildDir/test-results")
outputs.dir(reportsDir)
classpath = sourceSets["test"].runtimeClasspath
main = "org.junit.platform.console.ConsoleLauncher"
args("--scan-classpath")
args("--details", "tree")
args("--reports-dir", reportsDir)
}
}
project(":00") {
configure<ApplicationPluginConvention> {
mainClassName = "net.retrotexts.aj.lesson00.Hello"
}
}