Sharing build logic, what solution to choose?


I am currently using for a project the allprojects{} and subprojects{} build script features to do some shared build logic and configuration, but I’m not really happy with that.
So I dug a bit in the documentation, and found out the possibility to do it more cleanly would be use shared scripts via the buildSrc as explained here:
However, I found out as well in plenty of repos that some Gradle files are simply put in the Gradle folder and applied with an apply from: 'gradle/some script.gradle

So the question is: what is the difference between the 2 mechanisms? Should we favor always the first solution, or are there some criteria to choose one or the other?


There is a new chapter in the 6.8 docs on this topic with a much bigger sample app I found it very useful for answering this question

The convention plugin approach is the best one because you can write convention plugins that respond to the presence of certain other plugins and makes it possible to have consistent approach to writing build files across projects and repos. I found this sample which really clued me into how powerful the approach can be. Although I am writing my plugins in Java not Kotlin or Groovy.

Thanks @asaikali this is really interesting, and it’s good to get a more concrete example in the documentation (as they are sometimes a bit too simple).
Still I don’t get the added value of using the buildSrc folder (which is not even mentioned in the linked page) :sweat_smile: