Can a toolchain plugin be applied in a global init script?

Rather than applying the toolchain plugin in settings.gradle like:

plugins {
   id 'org.gradle.toolchains.foojay-resolver-convention' version '0.6.0'
}

as I have many (100+) projects is it possible to instead apply it to all projects via a global init script in ~/.gradle/init.d?

Within an init script I already have a

settingsEvaluated { settings ->
    settings.pluginManagement {
       repositories {
       }
   }
}

block to configure where to download plugins from in addition to the Gradle Plugins Portal, rather than having a pluginManagment block in the settings.gradle file in each project, but there doesn’t appear to be an equivalent

settingsEvaluated { settings ->
    settings.plugin {
   }
}

You can probably do settings.apply(...).

But be aware that like with the repositories from the init script, you make it practically impossible to share your Gradle projects as others would not have that configuration and you are modifying also any 3rd party builds you might be executing and thereby maybe break the build in subtle or not so subtle ways.

If you only ever run your own Gradle builds and also don’t share those Gradle builds, that might be not relevant for you and you should be able to use settings.apply(...).

@Vampire could you advise on how to use that settings.apply() for configuring a plugin? I tried the below, but it didn’t work:

settingsEvaluated { settings ->
    settings.apply {
        plugins {
            id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
        }
    }
}

You cannot use a plugins { ... } block there, those only work top-level in the script directly.
And apply(...) is not the same as apply { ... }. :wink: