Slackbot
02/22/2022, 6:13 PMtony
02/22/2022, 6:41 PMZak Taccardi
02/22/2022, 6:43 PMbuildSrc an included build?Zak Taccardi
02/22/2022, 6:46 PMbuildSrc/ to buildSource/, and doing include(“buildSource”) - my code no longer compiles.
For example, I’m still in the process of migrating to version catalogs. So my Dependencies.GradlePlugins.android that are added to the root build.gradle.kts are no longer found.
buildscript {
dependencies {
classpath(Dependencies.GradlePlugins.android)
}Zak Taccardi
02/22/2022, 6:47 PMdependencies(project(“:buildSource”))Zak Taccardi
02/22/2022, 6:48 PM:buildSource as an included build?tony
02/22/2022, 6:52 PMZak Taccardi
02/22/2022, 7:07 PMid(“com.conventions.library.android” - but currently using the generated accessor - com.conventions.library.android. Do I lose this?
I also have some helper extension functions. For example:
// variant that will respect `local.properties
fun ProviderFactory.gradleProperty(project: Project, propertyName: String)
fun Provider<String>.mapBoolean(default: Boolean? = null): Provider<Boolean>
// looks up named task, or registers it if it does not exist
fun <T> TaskContainer.namedOrRegister(taskName: String): TaskProvider<T>
My initial thought is, after putting everything directly on the classpath like dependencies(project(“:buildSource”)) to break it up like :buildSource:helper-functions and :buildSource:plugins. Then only put :buildSource:helper-functions on the global classpath.
Or is there a better way to do this?tony
02/22/2022, 7:21 PMplugins {} for adding plugins from my included build. But I believe in making progress towards that incrementallyJavi
02/22/2022, 7:23 PMZak Taccardi
02/22/2022, 7:25 PMcom.conventions.library.android and navigate directly to that plugin, but that’s a side noteJavi
02/22/2022, 7:35 PMZak Taccardi
02/22/2022, 8:20 PM:buildSource:helper-functions // on `buildScript { .. } classpath
:buildSource:plugins
Is :buildSource a multi-project build, or are :buildSource:helper-functions and :buildSource:plugins each single project builds?Zak Taccardi
02/22/2022, 8:21 PMsettings.gradle.kts and gradle.properties configuration between each of these included builds. I could use symlinks I think - but would lose the ability to modify `settings`/`gradle.properties` differently between included builds (not sure if that is needed at all)Zak Taccardi
02/22/2022, 8:26 PM:buildSource:helper-functions
fun ProviderFactory.gradleProperty(project: Project, propertyName: String)
into :buildSource:plugins by making it a plugin, and changing the API to:
// original
providers.gradleProperty(project, "propertyName")
// original
providersEnhanced.gradleProperty("propertyName")
Where providersEnhanced (yes I need a better name lol) is a gradle extension.Zak Taccardi
02/22/2022, 8:27 PMtony
02/22/2022, 8:38 PMIs :buildSource a multi-project buildyes. You almost always want multi-project builds, with empty root projects, except for the most trivial cases for your helper functions, moving them into a plugin is probably the most idiomatic way to do it from gradle's perspective. We have a small handful of such modules left in our build, which we add to the root
buildscript.dependencies.classpath... One possible pattern for you is to have those modules be normal JVM library modules, add them as dependencies to your convention plugin modules, and ensure that a convention plugin (like com.mycompany.base-plugin is applied to all modules/projects in your main build. Thus you have your utility functions available everywhere.
Having said that, what you should really strive for is declarative build scripts that don't use those functions directly at all. Rather, your plugins use them, and you elide this question entirelytony
02/22/2022, 8:38 PMZak Taccardi
02/22/2022, 8:49 PM// root (main) settings.gradle.kts
includeBuild(":buildSource) // multiproject
where the multi-project consists of two subprojects:
• :buildSource:plugins
• :buildSource:helper-functions
And the main build’s root build.gradle.kts file declares:
buildscript {
dependencies {
classpath(project(":buildSource:helper-functions"))
}
}
And slowly migrating away from :helper-functions into :plugins where possible.
I’m guessing it would be good to break apart :plugins eventually into dedicated subprojects for each plugin, too?Zak Taccardi
02/22/2022, 8:53 PM:plugins would affect the main build. With buildSrc this is easy - everything invalidates the main build!
For example, if I add a new internal fun within :plugins - did I just invalidate my entire main build, given that internal is package private, so to java code it’s a public API change?tony
02/22/2022, 10:03 PMtony
02/22/2022, 10:04 PM// settings.gradle
pluginManagement{
includeBuild(":buildSource")
}
This is the preferred way to include build that provide plugins. And it's the only way if you want to include builds that provide Settings plugins