Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle's central declaration for plugins block?

Latest Gradle version, 7.0, introduced a feature of central declaration of dependencies. You can now declare your dependencies (versions, libraries or even sets of related libraries - bundles) in a separate file and use them across whole, even multi-module, project:

# libs.versions.toml

[versions]
kotlin = "1.4.32"
tgbotapi = "0.33.3"

[libraries]
tgbotapi-core = { group = "dev.inmo", name = "tgbotapi.core", version.ref = "tgbotapi" }

[bundles]
tgbotapi = ["tgbotapi-core"]
// And then in your build.gradle.kts
dependencies {
    implementation(libs.bundles.tgbotapi)
}

However, I cannot make this feature work with the plugins block:

plugins {
    kotlin("jvm").version(libs.versions.kotlin).apply(false) // Unresolved reference: libs
}

How do i use this central declaration for plugins?

like image 440
madhead - StandWithUkraine Avatar asked Jan 01 '26 11:01

madhead - StandWithUkraine


1 Answers

You can use

plugins {
    alias(libs.your.library) apply false
}

to add plugins. Your Kotlin version notation should also work though. You could also add this to your libs.versions.toml:

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }

and then:

plugins {
     alias(libs.plugins.kotlin.jvm) apply false
}
like image 64
Maddin Avatar answered Jan 03 '26 12:01

Maddin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!