Hello,
I’ve created a java-application project via gradle cmd line using JDK 25. I’ve made some minor modifications to the sub projects ‘app’, ‘list’, and ‘utilities’. I also added the following to \gradle\libs.versions.toml
[versions]
commonsTextVersion = "1.15"
junitVersion = "6.1"
[libraries]
commons-text = { module = "org.apache.commons:commons-text", version.ref = "commonsTextVersion" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junitVersion" }
and the \buildSrc\src\main\kotlin\buildlogic.java-common-conventions.gradle.kts was updated to:
plugins {
`java-library`
`distribution`
`eclipse`
}
dependencies {
constraints {
// Define dependency versions as constraints
// original
// implementation("org.apache.commons:commons-text:1.14.0")
// using val declarations in same gradle.kts file
// implementation("org.apache.commons:commons-text:${commonsTextVersion}")
// FAILED 'Unresolved reference 'libs'
implementation(libs.commons.text)
}
// Use JUnit Jupiter for testing.
// testImplementation("org.junit.jupiter:junit-jupiter:6.0.1")
// testImplementation("org.junit.jupiter:junit-jupiter:${junitVersion}")
// FAILED 'Unresolved reference 'libs'
testImplementation(libs.junit.jupiter )
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
both the build.gradle.ktsand settings.gradle.ktswithin buildSrc are untouched.
When I run any gradle task clean/run/build, I get 'Unresolved references ‘libs’. Searching on Google, didn’t find anything useful. Is it possible to use to libsin the buildlogic*.gradle.kts or I can only use them in build.gradle.kts in the root of the main project? I’d like to declare a list versions in one place and use partial subset in each of my sub-projects. I thought the libs.versions.toml would allow that especially the bundles section seems very handy and tidy.
Thanks,
Tommy
[EDIT] Here’s the error:
d:\Dev\_projects_\java\vu>%GRADLE_HOME%\bin\gradle clean
> Task :buildSrc:compileKotlin FAILED
e: file:///D:/Dev/_projects_/java/vu/buildSrc/src/main/kotlin/buildlogic.java-common-conventions.gradle.kts:118:18 Unresolved reference 'libs'.
e: file:///D:/Dev/_projects_/java/vu/buildSrc/src/main/kotlin/buildlogic.java-common-conventions.gradle.kts:124:21 Unresolved reference 'libs'.
[Incubating] Problems report is available at: file:///D:/Dev/_projects_/java/vu/build/reports/problems/problems-report.html
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':buildSrc:compileKotlin' (registered by plugin class 'org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper').
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.btapi.BuildToolsApiCompilationWork
> Compilation error. See log for more details
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights from a Build Scan (powered by Develocity).
> Get more help at https://help.gradle.org.
BUILD FAILED in 2s
8 actionable tasks: 2 executed, 6 up-to-date