Configure logging with the JVM Test Suite Plugin

I’ve been converting a project to use this incubating plugin. It did use the testLogging closure to configure what logs to show. I tried to import that closure into the test closure, but it isn’t accepted there. The plugin documentation doesn’t mention anything about configuring logging. How can I achieve this?

testLogging is a configuration of the test task.
So within the configuration for the test suite in question you would do something like

targets.configureEach {
    testTask {
        testLogging...
     }
}
1 Like

I can’t get Gradle to be happy with that. This is for the built-in test task. My configuration currently is

testing {
	suites {
		test {
			useJUnitJupiter()
			dependencies {
				implementation project()

				// Provides JUnit, Spring Test, AssertJ, Hamcrest, Mockito, JSONassert, & JsonPath
				implementation "org.springframework.boot:spring-boot-starter-test"
			}

			targets.configureEach {
				testTask {
					testLogging {
						events = ['FAILED', 'SKIPPED']
						exceptionFormat = 'full'
					}
				}
			}
		}
	}
}

With this, I get the error message Could not find method testTask() for arguments [build_1fh1351cdm5238ctn1qga65kf$_run_closure12$_closure36$_closure37$_closure39$_closure40@3a5df386] on object of type org.gradle.api.plugins.jvm.internal.DefaultJvmTestSuiteTarget.. I tried changing testTask to just test but that resulted in what seems to be a very similar error message: Could not find method testLogging() for arguments [build_1fh1351cdm5238ctn1qga65kf$_run_closure12$_closure36$_closure37$_closure39$_closure40$_closure41@19b06964] on object of type org.gradle.api.plugins.jvm.internal.DefaultJvmTestSuite.

I highly recommend switching to Kotlin DSL. By now it is the default DSL, you immediately get type-safe build scripts, actually helpful error messages if you mess up the syntax like here, and amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio.

What I showed was Kotlin DSL. For Groovy DSL you need to use testTask.configure { instead of testTask {

I didn’t know the Kotlin DSL is now the default. That’s going to require some training. But adding .configure did fix this build, thank you!

Yep, since 8.2: Kotlin DSL is Now the Default for New Gradle Builds