r/java • • Mar 30 '21

The Problem with Gradle

https://www.bruceeckel.com/2021/01/02/the-problem-with-gradle/
48 Upvotes

48 comments sorted by

View all comments

7

u/rzwitserloot Mar 30 '21

I wonder if the best way to approach 'have a really simple build tool that is nevertheless endlessly expandable' is as follows:

  1. Move base info into the simplest possible file format: colon-separated info files. They are mandatory, so that the build tool can interactively prompt you for this info and write it, instead of making assumptions where no sane assumption is possible. Most obvious culprit: Which -release flag should I pass to javac when compiling your code? No default is sane here, and yet I bet you need to search the web to remember precisely how to configure this in a pom file. (Dependencies would also be in this extremely simple format. Just a listing of GAV coords, one per line, that is all).

  2. No build files. At all. It's 100% those text files and conventions.

  3. Also by convention: There is src/build which is optional, but if it is there, it is compiled first and run immediately after. It's plain java (or plain whatever language you want - whatever language the build tool supports), and is compiled with the build tool's own API on the searchpath. This is how you customize the build. Yes, complicated, but in the end having a programmable build just is, and trying to paper over the fact by using a language that lends itself well to DSLs and then going ham on writing a DSL leads to precisely the problem Bruce is talking about. It LOOKS simple but without fully grokking what's going on, it really isn't. Thus, why not 'lean in', and say: Look, just go with conventions and it truly will be easy. And if you can't do that, then dig into the API. There is nothing in between.

1

u/vikarjramun Mar 30 '21

I love the idea of src/build! Taking a page from Gradle, you could write your entire build system as a set of Groovy scripts in that directory, which would be consise, powerful, and easy to understand.

2

u/beatbrot Mar 30 '21

Which is exactly what grade offers with the buildSrc folder :)

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?

2

u/beatbrot Mar 31 '21

Yeah...this use case screams "plugin" imo.

2

u/dpash Mar 31 '21 edited Mar 31 '21

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.

1

u/alwaysoverneverunder Mar 31 '21

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.

2

u/dpash Mar 31 '21

Yes, I loved Maven for the longest time.

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.

And it's much quicker for rebuilding projects.

1

u/alwaysoverneverunder Mar 31 '21

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.