Is it possible to import a Gradle file with a plug...
# gradle
e
Is it possible to import a Gradle file with a plugin statement without getting unresolved references? I want to decompose my build.gradle.kts.
e
I can not figure out how to use plugins and the version catalog in the convention plugins without getting unresolved references. I do not want a subprojects. I have these files, among others:
buildSrc/settings.gradle.kts
Copy code
dependencyResolutionManagement {
    versionCatalogs {
        create("libs") {
            from(files("../gradle/libs.versions.toml"))
        }
    }
}
buildSrc/build.gradle.kts
Copy code
plugins {
    `kotlin-dsl`
    `kotlin-dsl-precompiled-script-plugins`
}

repositories {
    mavenCentral()
}
buildSrc/src/main/kotlin/jooq.gradle.kts
Copy code
internal val Project.libs: VersionCatalog get() =
 project.extensions.getByType<VersionCatalogsExtension>().named("libs")

plugins {
    alias(libs.findPlugin("jooq-codegen-gradle").get())
}
dependencies {
    jooqCodegen(libs.jooq.meta.extensions)
    jooqCodegen(libs.jooq.meta.kotlin)
}
jooq { [configs] }
I get
Unresolved reference: libs
for the last file.
e
Copy code
// buildSrc/build.gradle.kts
dependencies {
    implementation("org.jooq.jooq-codegen-gradle:org.jooq.jooq-codegen-gradle.gradle.plugin:3.19.9")
}
Copy code
// buildSrc/src/main/kotlin/jooq.gradle.kts
plugins {
    id("org.jooq.jooq-codegen-gradle")
}
e
is it not possible to use the version catalog in
gradle/libs.version.toml
? you hard-coded the version.
e
1. plugin dependencies are resolved before your plugin is applied, so you can't just add stuff to the buildscript classpath with a normal
plugins
declaration, it needs to be a runtime dependency of your plugin 2. unfortunately https://github.com/gradle/gradle/issues/17963 is unresolved so you can't directly use
libs.plugins.*
. you can find workarounds in that issue though
also this doesn't really have anything to do with kotlin, see the channel topic
🙏 2
v
As the last question was about the hard-coded version, yes you can use the version catalog in
buildSrc/build.gradle.kts
instead of using a hard-coded version. You just have to declare it in the settings script, because by default the
buildSrc
build has its own version catalog like any other build.