Closed
Description
This was previously reported as part 2 of Issue 16652.
Expected Behavior
I expect centralized dependency versions to work everywhere I specify dependencies. This includes my buildscript
clause.
In myproject/settings.gradle.kts
:
enableFeaturePreview("VERSION_CATALOGS")
...
In myproject/gradle/libs.versions.toml
:
[libraries]
shadowJarPlugin = "com.github.jengelman.gradle.plugins:shadow:6.1.0"
In myproject/build.gradle.kts
:
buildscript {
dependencies {
classpath(libs.shadowJarPlugin)
}
}
...
Current Behavior
> Configure project :
e: /Users/jwilson/Development/myproject/build.gradle.kts:20:15: Unresolved reference: libs
Context
I’m using Gradle 7.
Workaround
This is a workaround. It is verbose, doesn’t have IDE support, and is inconsistent with my other dependencies blocks.
buildscript {
fun libs(lib: String): String {
val versionCatalog = project.extensions.getByType(VersionCatalogsExtension::class).named("libs")
val dep = versionCatalog.findDependency(lib).get().get()
return "${dep.module.group}:${dep.module.name}:${dep.versionConstraint.displayName}"
}
dependencies {
classpath(libs("shadowJarPlugin"))
}
}