Martin
11/02/2024, 12:10 PMsettings.gradle.kts ?
// build.gradle.kts
buildscript {
dependencies {
// ...
}
// Can I move this to settings.gradle.kts?
repositories {
mavenCentral()
}
}
This is possible for plugins{} and regular dependencies but I haven't found a way for buildscript {} . Is there a way?Vampire
11/02/2024, 3:36 PMbuildscript blocks at all. 🙂
Besides that, I'm not sure whether the plugin repositories are also used for that? If not, it might be possible with gradle.beforeProject { ... }.Thomas Broyer
11/02/2024, 9:50 PMpluginManagement.repositories are used for buildscripts yes (I have to use buildscript to add the JDBC driver when using the Martin
11/02/2024, 9:52 PMMartin
11/02/2024, 9:54 PMA problem occurred configuring root project 'tmp'.
> Could not resolve all artifacts for configuration ':classpath'.
> Cannot resolve external dependency org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20 because no repositories are defined.
Required by:
root project :Martin
11/02/2024, 9:55 PMpluginManagement {
repositories {
mavenCentral()
}
}
build.gradle.kts
buildscript {
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20")
}
}Thomas Broyer
11/02/2024, 10:29 PMbuildscript with dependencies and no single repositories since Gradle 5.0 in the project I'm looking at (so no pluginManagement at the time! settings script only declared subprojects and the root project's name; that was nearly 6 years ago); I don't even understand how/why it works 🤣
The project has since been updated to Gradle 8.4 and repository declarations centralized in the settings script (and at some point pluginManagement.repositories was added to add mavenCentral() in front of gradlePluginPortal() to bypass JCenter) and this has continued to work throughout without any buildscript.repositories ever added 🤷
Maybe it works because the build script also includes a plugins {} block then?Vampire
11/02/2024, 10:58 PMapply falseVampire
11/02/2024, 11:01 PMbuildSrc dependency, or you could have an included build with a no-op plugin that has it as dependency and then apply that.Martin
11/02/2024, 11:09 PMplugins {} block then?
OMG this is it!Martin
11/02/2024, 11:11 PMbuildscripts 😂Vampire
11/02/2024, 11:12 PMlifecycle-base?
Not exactly no-op, but the bottom-most built-in one.Vampire
11/02/2024, 11:12 PMbuildscript block 🙂Martin
11/02/2024, 11:12 PMplugins {} stuff, now I like buildscript {} betterMartin
11/02/2024, 11:13 PMbuild-logic included build, I already have the gav for themVampire
11/02/2024, 11:13 PMMartin
11/02/2024, 11:13 PMVampire
11/02/2024, 11:13 PMMartin
11/02/2024, 11:14 PMVampire
11/02/2024, 11:14 PM<plugin-id>:<plugin-id>.gradle.plugin:<plugin-version>Martin
11/02/2024, 11:14 PMMartin
11/02/2024, 11:14 PMVampire
11/02/2024, 11:15 PMMartin
11/02/2024, 11:16 PMlibs.plugins in dependencies?Martin
11/02/2024, 11:16 PMdependencies {
implementation(libs.kotlin.gradle.plugin)
}
?Vampire
11/02/2024, 11:16 PMMartin
11/02/2024, 11:16 PMMartin
11/02/2024, 11:17 PMVampire
11/02/2024, 11:19 PMimplementation(plugin(libs.plugins.versions))
with the function being
fun DependencyHandlerScope.plugin(plugin: Provider<PluginDependency>) = _plugin(plugin)
fun GradleDependencies.plugin(plugin: Provider<PluginDependency>) = _plugin(plugin)
private fun _plugin(plugin: Provider<PluginDependency>) = plugin.map {
val version = if (it.version.requiredVersion == "embeddedKotlinVersion") embeddedKotlinVersion else it.version.requiredVersion
"${it.pluginId}:${it.pluginId}.gradle.plugin:$version"
}Vampire
11/02/2024, 11:19 PMVampire
11/02/2024, 11:21 PMMartin
11/02/2024, 11:23 PMMartin
11/03/2024, 11:31 AMbuild-logic included build, this works in `build.gradle.kts`:
buildscript {
dependencies {
classpath("build-logic:build-logic:2.0.20")
}
}
But not in build.gradle because Gradle doesn't know how to resolve kotlin-stdlibVampire
11/03/2024, 5:13 PMVampire
11/03/2024, 5:13 PMVampire
11/03/2024, 5:14 PMMartin
11/03/2024, 6:16 PMbuild.gradle.kts already has kotlin-stdlib so (I guess), it doesn't try to resolve it. But build.gradle tries and fails (because no repositories in buildscript {} ).Martin
11/03/2024, 6:17 PMVampire
11/03/2024, 7:47 PM