This message was deleted.
# community-support
s
This message was deleted.
t
❤️ 1
z
one of my favorite posts! I probably should I have asked my question differently - it’s more about what are the differences. i.e. - what features do I lose when making
buildSrc
an included build?
After renaming
buildSrc/
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.
Copy code
buildscript {
 dependencies {
   classpath(Dependencies.GradlePlugins.android)
}
I guess I would change the above to something like:
Copy code
dependencies(project(“:buildSource”))
Or does that defeat the whole purpose of
:buildSource
as an included build?
t
ish? Might be a worthwhile incremental step forward. First step is always to get your code to compile, then iterate to make it compile faster 🙂
👍 1
z
so there’s really 3 pieces of logic that I need to be migrated: • dependencies/versions (handled by version catalogs, so we’re good here) • helper functions • plugins It seems that plugins will be handled automatically. I have plugins like
id(“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
Copy code
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
Copy code
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?
t
we actually do exactly that right now. My goal is to get rid of such helper functions entirely and rely solely on
plugins {}
for adding plugins from my included build. But I believe in making progress towards that incrementally
👍 1
j
you lose accessor generation but you can create plugin aliases if you migrate to catalogs
👍 1
z
oh nice! I would like to see enhanced IDE navigation for plugin aliases in that case. Would be nice to be able to cmd + B
com.conventions.library.android
and navigate directly to that plugin, but that’s a side note
j
IDE support has a long way to be completely polished. No wrong unresolved references, toml autocomplete, shortcut navigation to original files and not generated files and so on
👍 1
z
question for you @tony : Given the following design:
Copy code
: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?
I also need to figure out the best way to share
settings.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)
and I could migrate code from
:buildSource:helper-functions
Copy code
fun ProviderFactory.gradleProperty(project: Project, propertyName: String)
into
:buildSource:plugins
by making it a plugin, and changing the API to:
Copy code
// original
providers.gradleProperty(project, "propertyName")

// original
providersEnhanced.gradleProperty("propertyName")
Where
providersEnhanced
(yes I need a better name lol) is a gradle extension.
just throwing this stuff out there to make sure I’m headed in the right direction
t
Is :buildSource a multi-project build
yes. 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 entirely
👍 1
❤️ 1
we have a lot of redundancy in our explosion of settings.gradle scripts, unfortunately. Right now I just live with it.
👍 1
z
so structure becomes:
Copy code
// 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:
Copy code
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?
one thing I don’t get though is how classpath changes to
: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?
t
I don't quite recall, I think there may be some Kotlin ABI analysis that would prevent that, but you can experiment pretty easily
for the included build, you might want
Copy code
// 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
💯 1