dependencies {
compileOnly libs.org.lombok
annotationProcessor libs.org.lombok
// Use JUnit Jupiter for testing.
testImplementation testLibs.org.junit // testLibs is not recognized
}
The build results in:
Build file '[...]/testing-layers/testing-layers-java/application/build.gradle' line: 2
An exception occurred applying plugin request [id: 'tmp.java-common-conventions']
> Failed to apply plugin 'tmp.java-common-conventions'.
> groovy.lang.MissingPropertyException: Could not get unknown property 'testLibs' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
That’s not correct @peter-galcik.
He is building his convention plugin as a Groovy DSL precompiled script plugin, so he can use testLibs fine, if it were available in the build where he applies it.
The hack-around is only necessary for Kotlin DSL precompiled script plugins.
The problem is, that testLibs is only defined in buildSrc settings script.
But you need to also define it in the project where you apply the convention plugin to.
The naming convention for the default libs catalog is only valid for the libs catalog.
The testLibs catalog you have to define manually also in the settings script of the build where you want to use it.
Thank you @Vampire , @peter-galcik
Looks like declaring testLibs in the root project is working.
Below the root settings.gradle:
dependencyResolutionManagement {
versionCatalogs {
testLibs {
from(files('./gradle/test-libs.versions.toml'))
}
}
}
rootProject.name = 'testing-layers-java'
include 'domain'
include 'application'
include 'infrastructure'
I’m now able to use testLibs both in the sub projects as well as in the convention plugin.
I’m not clear though as to why the testLibs catalog needs “special treatment” compared to the libs catalog.