Gradle Plugin Logging without the Gradle API

It certainly seems to be good practice to separate Gradle Plugin code into code and tests which do not depend on any Gradle API and Gradle Plugin specific code , see also

Logging for the Gradle API dependent code is straight forward and well supported.

For me it’s not quite clear, how to do logging in the Gradle independent code, like for example in without introducing a dependency to the Gradle API, also in terms of Logging Library to be used.

Or is this question academical? But then again, making basically domain layer code, dependent dependent on the Gradle API, seems to reduce the potential reusability.

Any suggestions, good practice, feedback?

You can use pretty much any logging framework you want. It’ll all get redirected appropriately. I’d probably suggest just using SLF4j, as that’s what Gradle’s API extends from. The only limitation is that you won’t have access to Gradle specific logging levels such as LIFECYCLE or QUIET.

1 Like

Great. I tested this in a Gradle Plugin project of mine and it works.

But in the Integration Tests - tests without any Gradle Dependencies - the following Standard Output is confusing me:

 SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/chhex/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-simple/1.7.29/82ae07f95088577987a15d90171de12b00d81847/slf4j-simple-1.7.29.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/chhex/.gradle/caches/5.0/generated-gradle-jars/gradle-api-5.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]

This even though i did’t see any gradle dependencies in the htmlDependency Report.

I have a configuration defined as follows:

val integrationTestRuntimeOnly: Configuration by configurations.getting {

and sl4j dependencies declared

dependencies {

So for me it is not quite clear why sl4j is finding multiple bindings, specially the one in the gradle-api

You’re not using gradleApi() for that project?

I am using the GradleApi for this project, it is a Gradle Plugin, but not for the Classes in Test, see the integrationTestRuntimeOnly Configuration.

Can you share how you are setting up your integration test task? Are you using testkit for these tests?

Great thanks for looking into this.
To answer your questions: yes the testKit is a testCompile Dependency
And here the build script:
And these the common "applied from: files: