we need something similar for our corporate proxy although it needs to be compatible with multiple versions of Gradle hence thinking it should be implemented in Groovy to avoid issues where e.g. getDependencyResolutionManagement is not available in earlier versions so I can wrap it in
Besides that it might be best if those projects use the proxy directly - unless you share those projects with others of course - I agree. If implemented as init script I would usually also use Groovy DSL. One point is compatibility with Gradle versions not yet supporting Kotlin DSL, the other point is what you mentioned, that you can more easily do Gradle-version specific code due to the duck-typing of Groovy.
However what isn’t clear from searching and reading the javadoc is the difference between gradle.beforeProject/afterProject and allprojects
The difference is described in the JavaDoc.
To best understand it, take a build with two projects and paste this in the root project build script:
gradle.beforeProject {
println("beforeProject ${this.path}")
}
gradle.allprojects {
println("allprojects ${this.path}")
}
gradle.afterProject {
println("afterProject ${this.path}")
}
You will see that like described in the JavaDoc, allprojects works on all projects, already existing ones and also ones added in the future. The other two only work from the point of adding on, so beforeProject will only be called for the subproject, afterProject will be called for the root and subproject.
When registering those from a settings or init script, there is not much difference as to which projects they apply to as you are still in initialization phase and they are only called at configuration phase. From there it is just when the code is called, before the build scripts or after them.
including any composite plugins
Not sure what you mean with “composite plugins”, but whether you mean composite build that builds a plugin or all composite builds is not really important. If you do it from the settings script, then not as the composite builds are stand-alone builds, if you do it from an init script then of course yes, because the init script is also applied to the composite build itself.
Which is preferred to use and why?
The one that best fits your use-case 