Has anyone out there used buildSrc or a custom dis...
# gradle
w
Has anyone out there used buildSrc or a custom distributions to enhance the gradle DSL via extension functions? I am thinking like this
Copy code
fun PluginDependenciesSpecScope.libraryPlugins(){
    id("java-library")
    id("io.freefair.lombok")
}
which could then be called in a project like
Copy code
plugins {
    libraryPlugins()
}
or better yet, an extension method that could be invoked at the root in the project script that could add plugins and dependencies all at once? For some reason, I just get unresolved references, even though my IDE thinks it is fine
m
I think the
plugins {}
block is very special, you cannot execute arbitrary kotlin code inside
☝️ 1
w
Hmm OK. Maybe an init script would be the way to go. Also, since the plugins block has constrained syntax, is a top level function possible?
g
To achieve this, you should use so called "convention plugin" approach, so you can create a custom plugin, which applies other plugins and configure them, and after that you apply only this plugin like `plugins { id("library-convention") } Using extension functions is not really an option with Gradle
The easiest way is to use precompiled script plugin for this
w
Ahhh OK bummer. Thanks! The reason I was hoping for this is to pass configuration options to the plugin code its self, and gradle extensions only really work after the configuration phase is done.
And just to make the conventions autocompletable
g
Convention plugin approach actually the only way to apply plugin and get autocomplete work as for plugin itself, same for provided configuration
I mean if you use precompiled script plugins If you use Kotlin DSL, you even have access to static accessors for plugins in buildSrc
w
I am making progress on this using an init script bundled in a custom gradle distribution
having trouble trying to add extensions to the settings model though
not extension functions, gradle extensions. Settings is supposedly extensions-aware