Daniele B
02/28/2023, 6:29 PMbuildscript {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin.version}")
}
}
But in the latest multiplatform samples, the buildscript section is not included anymore.
Does buildscript belong to an old way of configuring gradle, or is it still relevant today?
Previously, the documentation of popular libraries such as Kotlin Serialization or SqlDelight required to have a classpath specified as a dependency of buildscript, but now not anymore.Vampire
02/28/2023, 7:11 PMapply...
is legacy and not recommended since years.
Instead the plugins { ... }
block is the proper way to apply a plugin.Daniele B
02/28/2023, 7:27 PMpluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
}
plugins {
kotlin("multiplatform").version(extra["kotlin.version"] as String)
id("org.jetbrains.compose").version(extra["compose.version"] as String)
...
}
}
this in the *project*’s build.gradle.kts:
plugins {
kotlin("multiplatform") apply false
id("org.jetbrains.compose") apply false
...
}
and then recalling the plugins in all target-specific build.gradle.kts (e.g. shared, jsApp, wasmApp, desktopApp):
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
...
}
There seems to be quite a lot of duplication.
Should all plugins be defined in the project’s build.gradle.kts too? and what’s the meaning of apply false
?mbonnin
02/28/2023, 10:20 PMapply false
is used to put the plugin jar in the root project classpath (so that I think they are not loaded several times by different projects, but don't quote me on this...)
My rule of thumb is: put all your plugin jars in your buildSrc
/`build-logic` implementation configuration then use ids in individual projects.
I'm not sure about pluginManagement.plugins
. Looks like they're used to define versions but you could as well define them in your root project plugins {}
block and I think that'd work toobuildSrc
/`build-logic` , I guess root project, apply false
+ ids
in subprojects would work toobuildSrc
/`build-logic` allow you to factor your build logic with convention plugins and once you have a lot of modules, this becomes handyDaniele B
02/28/2023, 10:49 PMapply false
), but it gives me some gradle errors, so I think they need to be defined first in the pluginManagement.plugins
.
When I have more time, I might try to investigate the buildSrc
/`build-logic` way you suggest.
Many thanks!mbonnin
02/28/2023, 10:51 PMit gives me some gradle errorsInteresting. Can you share them? I'm curious what
pluginManagement.plugins
does now 🙂Daniele B
02/28/2023, 10:58 PMcom.android.application
plugin, not sure why:
Build file '/Users/daniele/Dev/KMP/PSF_CMS/build.gradle.kts' line: 13
Plugin [id: 'com.android.application', version: '7.3.0', apply: false] was not found in any of the following sources:
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.android.application', version: '7.3.0', apply: false] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:7.3.0')
Searched in the following repositories:
Gradle Central Plugin Repository
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.resolveToFoundResult(DefaultPluginRequestApplicator.java:238)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.lambda$resolvePluginRequests$3(DefaultPluginRequestApplicator.java:168)
at org.gradle.util.internal.CollectionUtils.collect(CollectionUtils.java:212)
at org.gradle.util.internal.CollectionUtils.collect(CollectionUtils.java:206)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.resolvePluginRequests(DefaultPluginRequestApplicator.java:166)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:101)
at org.gradle.kotlin.dsl.provider.PluginRequestsHandler.handle(PluginRequestsHandler.kt:48)
at org.gradle.kotlin.dsl.provider.StandardKotlinScriptEvaluator$InterpreterHost.applyPluginsTo(KotlinScriptEvaluator.kt:195)
mbonnin
02/28/2023, 11:00 PMSearched in the following repositories:
Gradle Central Plugin Repository
Weird, looks like it's not searching in the Google maven repo...pluginManagement.repositories {}
Daniele B
02/28/2023, 11:02 PMpluginManagement
section. I will now, put it back, without the plugin
subsectionmbonnin
02/28/2023, 11:03 PMgradlePluginPortal()
is thereDaniele B
02/28/2023, 11:05 PMmbonnin
02/28/2023, 11:24 PMplugins {}
is "special"Daniele B
02/28/2023, 11:58 PMmbonnin
02/28/2023, 11:59 PMDaniele B
03/01/2023, 12:08 AMVampire
03/01/2023, 12:08 AMDaniele B
03/01/2023, 12:13 AMVampire
03/01/2023, 12:14 AMDaniele B
03/01/2023, 12:15 AMmbonnin
03/01/2023, 12:17 AMVampire
03/01/2023, 12:17 AMbuild-logic/settings.gradle.kts
as it references the same version catalog for as the parent build. Separate build by default have separate files unless you configure it differently.Daniele B
03/01/2023, 12:23 AMVampire
03/01/2023, 12:24 AMDaniele B
03/01/2023, 12:25 AMVampire
03/01/2023, 12:26 AMDaniele B
03/01/2023, 12:27 AMVampire
03/01/2023, 12:27 AMDaniele B
03/01/2023, 12:30 AMVampire
03/01/2023, 12:31 AMDaniele B
03/01/2023, 12:40 AMlibs.versions.toml
in the root folder, with this content:
[versions]
kotlin = "1.8.0"
agp = "7.4.0-beta02"
compose = "1.4.0-alpha01-dev940"
ktor = "2.2.2"
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
but I can’t see how I can access this dataVampire
03/01/2023, 12:41 AMDaniele B
03/01/2023, 12:41 AMlibs.
in any gradle file, nothing comes upVampire
03/01/2023, 12:49 AMDaniele B
03/01/2023, 12:59 AMlibs.
nothing comes up, and now it complains about the existing plugins:
Build file '/Users/daniele/Dev/KMP/PSF_CMS/androidApp/build.gradle.kts' line: 1
Plugin [id: 'org.jetbrains.compose'] was not found in any of the following sources:
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'org.jetbrains.compose'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (plugin dependency must include a version number for this source)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.resolveToFoundResult(DefaultPluginRequestApplicator.java:238)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.lambda$resolvePluginRequests$3(DefaultPluginRequestApplicator.java:168)
at org.gradle.util.internal.CollectionUtils.collect(CollectionUtils.java:212)
at org.gradle.util.internal.CollectionUtils.collect(CollectionUtils.java:206)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.resolvePluginRequests(DefaultPluginRequestApplicator.java:166)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:101)
at org.gradle.kotlin.dsl.provider.PluginRequestsHandler.handle(PluginRequestsHandler.kt:48)
at org.gradle.kotlin.dsl.provider.StandardKotlinScriptEvaluator$InterpreterHost.applyPluginsTo(KotlinScriptEvaluator.kt:195)
plugins {
id("org.jetbrains.compose")
id("com.android.application")
kotlin("android")
}
Vampire
03/01/2023, 1:01 AMDaniele B
03/01/2023, 1:08 AMlibs.
!!!Vampire
03/01/2023, 1:16 AMbuild-logic
build as I mentioned previously.
Actually, I don't think the docs are confusing there, but if your think so, you should open an improvement issue about it.Daniele B
03/01/2023, 1:28 AM