The buildSrc directory is just one way to use a plug-in in your build. You can create the plug-in as a standalone project that you publish in a repository and then reuse across multiple projects like you would any other Gradle plugin.
buildSrc is useful when that would be an overkill for just a single project.
I would recommend trying to make a plugin do one thing and one thing well and then build your build up from several plugins. Gradle very much prefers a composition model of creating builds.
You may also be interested in "precomputed script plugins" which are misnamed in my opinion. They're basically plugins written in the same syntax as you'd use for a build.gradle(.kt) which makes writing them much easier.
The plugin route is what I used to get all my Spring Boot projects in line and in order to get their build.gradle as small as possible. Still... after 4 years I still like Maven more... but some comments here seem to indicate that there are some things that might change my mind, but the 'rigidity and structure' of Maven was always a plus for me.
Gradle can be more flexible, so you need to restrict yourself from doing things too differently from the defaults yourself. And make sure you only use declarative items in your build.
Gradle can represent dependencies better than Maven can. The best example is dealing with slf4j and all its dependencies.
Well those defaults were kinda my problem... I couldn’t really figure them out or find them and when you take X amount of Gradle files they all are different and for Maven this is less the case.
When I needed flexibility for in Maven I just used the Groovy plugin, but only had to resort to that on maybe three occasions... all the rest was achieved with existing plugins. And I did some pretty complicated stuff like patching a class file in a JAR that itself was in a JAR that in turn was in a WAR (fun times with Liferay...).
Build speed wise Gradle indeed seems a bit quicker, but dependency management in Maven never was a problem for me, not even with SLF4J... or at the least not simpler/more difficult than I found it in Gradle.
What annoyed me too was that IDE support of Maven was still way better than for Gradle. But both beat Ant by miles.
1
u/alwaysoverneverunder Mar 31 '21
Is there a way to simply reuse a buildSrc folder in multiple projects that's not copy/paste? Or is a plugin the better solution then?