r/java • u/siimon04 • Jan 17 '21
The problem with Gradle: really?
https://melix.github.io/blog/2021/01/the-problem-with-gradle.html123
u/Grung Jan 17 '21
The author makes fine points if you want the build system to be something you live and breathe just like the programming language that you use day-to-day, but that isn't what I want, and I'm guessing it's not what most developers want.
I don't want to spend the same amount of effort to understand a build tool that I do to understand the language I'm developing in. I want to spend, say, 5% of that effort. I need to be able to make relatively simple and moderately complex changes to a build without learning something as complex as a new programming language, and gradle just doesn't allow that.
In regards to "many ways to do things" this is a problem specifically with readability. I can't read gradle scripts. Don't get me wrong, I can read the basics, but I don't use it often enough to internalize enough of the details to read anything past the most simple, common elements.
The fact that there are many different ways the tool is used is a huge barrier to picking up more of it. Googling for examples is mostly a useless endeavor, because so many results are using entirely different paradigms to configure their own projects. There's not enough commonality to make it easy to pick up anything even slightly non-trivial.
7
u/preskot Jan 17 '21 edited Jan 17 '21
I’d argue that you do actually need just 5 mins. for most type of the project build use cases with Gradle. Building a lib, fat jar or a war file is quite trivial.
Yes, I’ve been deep in the Gradle rabbit hole when wanting to do something custom, like generating files on build or rule based multi-project shared deps. The ability to write your own tasks has only helped me.
I like Gradle a lot and its perf has improved significantly since v6. If I find a better tool, I’ll switch, but for now I’m happy with it.
31
u/Grung Jan 17 '21
Yes, truly trivial things are trivial, but that's rarely what you Google for.
And plugins don't help readability, unless you're intimately familiar with the specific plugins already. I've spent time trying to figure out something on Google only to find out it was a local custom plugin. And to figure the plugin out, I'd have to go find it, and then learn to read yet another language, just to make a slightly more than trivial change.
Give me make any day.
4
u/Kernel_Internal Jan 17 '21
I've been adding make to a dockerized php/drupal project running in aws and I would say that the same general thing you're complaining about gradle is true of make; it's actually a little difficult to find easily digestible examples/docs by googling. I have found all sorts of excessively verbose manuals, but I know generally what I want to do and finding examples that don't start off with the programming equivalent of "to bake an apple pie, first you have to invent the universe" was a little frustrating. The point to note, I suspect, is that I'm new to make and you're new(ish) to gradle.
1
u/Prod_Is_For_Testing Jan 19 '21
One time I spent a whole day trying to make a fat jar because I didn’t know that you had to specifically invoke that task. None of the tutorials mentioned that. I assumed that all tasks would run on build
64
u/mahamoti Jan 17 '21 edited Jan 17 '21
Yes, really.
This entire article is an antipattern in our industry. Someone doesn't grok a tool and writes about it, followed by one of the tool's authors writing a response in defense that often boils down to "you're looking at it wrong."
"Think of gradle not as programming, but as configuring plugins" sounds amazing, until you can't easily discover the inputs and outputs of the built-in plugins, imported plugins all work differently with the built-in plugins and each other, and none of it is well documented.
The problem with build tools being complicated to solve complicated problems is, you don't spend as much time in them per-project as you do the rest of the codebase. So by the time you spin up another project, you may need to re-learn all the gotchas you fought through on the last project.
14
u/thedomham Jan 17 '21
"Think of gradle not as programming, but as configuring plugins" sounds amazing
That's actually why I love Gradle. I have dealt with disgustingly complex and project-specific built processes, where the requirements felt like their are so ancient and vile, that they might as well have been forged in hell.
Gradle is quick and easy for projects that follow conventions and aren't complete f**king nightmares. For those extremely complicated projects it was great having a full programming language with all the tooling at hand. You can just use a debugger on your build script, just like any old code.
The biggest problem is probably the middle ground. That being said, while I really do like Gradle and much prefer it to Maven, it's inner workings are pretty opaque at times and all important interfaces have major faults and there's no straight-forward way I know of to really learn Gradle. It requires a lot of trial and error, patience and poking around in Gradle's source code.
21
u/PartOfTheBotnet Jan 17 '21
You can just use a debugger on your build script, just like any old code.
Just the thought of having such a complicated build script that I would need to attach a debugger to it gives me shudders.
5
u/thedomham Jan 17 '21
Well yes and no. Even if your build process is rather simple, why wouldn't you introspect the state of your build when you run into an issue? You don't necessarily need to attach a debugger - but you can. I didn't need to use a debugger in aforementioned project. It could all have been done using log statements and critically looking at the code, but that would have been the slower, less efficient route.
That being said, the build process of that project was just so complex and maybe half of it wasn't even technically necessary and was just there because someone decided that we have to follow our own weird conventions.
Story time: One of those things that wasn't technically necessary was that one of the build artifacts had to be (additionally to a dedicated artifact server) be stored on a network drive. Simple copy task, nothing fancy, nothing complicated, but feels kinda wrong. For some very secret and domain specific reasons that artifact became a lot larger over time. At some point it was nearly 10gb large and while copying it to that network drive has always been quite slow, it now sporadically completely hung up and I was tasked with fixing the issue.
So I tried to find out where to start. Gradle doesn't offer any obvious way to display file copy progress. There's a way to log whenever a file is copied, but my task copied a single archive. Naive approach? Write my own copy task. Create two FileChannels, incrementally copy a certain percentage of the file and log how much was copied. Easy.
First try: That copy step took 10s instead of the usual 30min. I assumed that it was just the Gradle configuration time and that it didn't copy anything, especially since the default behavior of Gradle when copying nothing is to ignore it's obvious failure. So I added some more logging and a failure if nothing was copied. Tried again, same result. So I assumed that the copy I created was an empty file - peeked in the directory but everything looked okay. Deleted it, retry, same result. Does it unpack? Yes.
So what happened? I have no clue. Apparently the default Gradle Copy task had some issue with copying over the network. What I intended to be a temporary fixture to find out where the problem is became the permanent solution.
I don't work there anymore, but I'm pretty sure that custom copy task is still there.
0
u/hpernpeintner Jan 17 '21
You never needed to automate sth or assemble sth other than a simple fatjar, slight chance? About half of all the projects i did required slight changes to the workflow or the automation. When will people learn that its best to automate about everything and have a tool in the toolbox thats capable to do that instead of writing shitty ci plugins and checked in shell scripts.
38
u/handjobs_for_crack Jan 17 '21 edited Jan 17 '21
Let's say I need a build tool. Usually I expect to not spend more than day on establishing my builds for a project which would run for a year for a dozen engineers. Maybe two, if it's complicated enough. So, 12 * 12 * 20 work days, out of which 2 is 0.034% of our time. Spending five days learning how to do gradle builds and then taking another 2 days to actually implement them would grow our time spent doing builds by 250%. And for what?
The only time I really had a problem with maven was 12 years ago when we wanted to use a technology which was very young at the time and because we were very unlucky with two bugs working in tandem to stop me from doing things the way I wanted to.
I used to dislike maven, but since it's been stable and has been supported by everyone, I've not once seen an actual reason to use gradle, except for CV padding.
We manufacture so many problems to look for solutions, which provide any sort of benefit only in such marginal cases that you only come through them once every ten years or so.
4
u/geordano Jan 18 '21 edited Jan 18 '21
Couldn't agree more, truly reflects my experience as well. Build tool is something you never have to fight with, you just configure it once and forget about it.
Maven does a marvelous job with that, never in my entire career (15+ yrs) have I needed to look for alternative (let alone Gradle).
4
u/cogman10 Jan 18 '21
For a plain jane Java project, I do prefer maven. Gradle really shines when you aren't dealing with that.
If you want java + kotlin + some annotation libraries (like Dagger or immutables), things get really messy and hard to understand with maven fast.
With gradle, that same project is very straight forward, define your annotation processing modules in kapt and you are done.
Obviously my fear with gradle is the same others are talking about. It IS a programming language that's turing complete. That means that you can happily recreate ANT in gradle without a care in the world. In maven, doing that sort of crap is possible (with the ant plugin) but a whole lot more painful.
For me, it comes down to trust. Gradle is something I'd never trust to a novice because they'll abuse the hell out of it. Maven makes that abuse nearly impossible.
2
u/Orffyreus Jan 20 '21 edited Jan 20 '21
Maven allows you to write "archetypes" and deploy them or install them in your local repository. Archetypes are like project templates (and can also be created based on a project), so things like configuring the shade plugin (for fat jars) can be done once and reused for every new project: https://maven.apache.org/guides/introduction/introduction-to-archetypes.html
And annotation processing works out of the box with maven. If you want to use Immutables or MapStruct, you just declare its dependencies:
<dependencies> <dependency> <groupId>org.immutables</groupId> <artifactId>value</artifactId> <version>2.8.8</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct</artifactId> <version>1.4.1.Final</version> </dependency> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>1.4.1.Final</version> <scope>provided</scope> </dependency> </dependencies>
11
u/muffinluff Jan 17 '21
Imo, he dismisses the critic point of many ways to do the same thing in gradle, without giving any good explanation.
Configuring the build script should have a canon way of doing specific things. When I see a build.gradle file on the web that configures a plain java library I sometimes need to sit down and connect the dots to understand.
Imo, gradle should add the option of a flag in settings.gradle that would cause the build to fail if the build file doesn't conform to strict linting rules.
7
u/bedobi Jan 18 '21
Gradle projects require a PhD in Gradle AND intimate familiarity with the tastes of whoever implemented that particular project .gradle files likes to use it.
Frustrated with Gradle, our team has switched back to Maven, even for Kotlin projects. When we inherit codebases from other teams, often one of the first things we do is convert it from Gradle to Maven.
I honestly couldn't care less about how flexible and powerful Gradle is compared to Maven. Maven is simple, the same in every project (this is huuuuuge), just works and gets out the way.
3
u/warpspeedSCP Jan 17 '21
My only real gripe with gradle is that it has the most annoying tooling api ever.
9
u/GreemT Jan 17 '21
Thinking that Gradle is just about calling methods is the wrong mental model. Thinking that Gradle is "programming a build" is wrong. Gradle uses a programming language as a foundation for "configuration as code", but it is really about configuration, not programming.
I found this a very interesting point that I agree with. However, everytime I have to program something, I don't want a lot of hassle to create the code and the resulting code must be easy to understand. Probably everybody wants that right?
I created my first Gradle plugin a few months ago and it was a horrible experience. I had to figure out so much before I got it working correctly... I had to put comments on all kinds of code, because it was not clear at all why I needed some parts or why some methods needed to be used instead of others.
I have some frustrations with Gradle, but I do think that it is better than Maven. Gradle outperforms Maven by A LOT and the configuration possibilities are endless. If only Gradle had an easier learning curve and a clearer / easier to use API, it would be the best build tool for sure.
20
u/agentoutlier Jan 17 '21
Gradle outperforms Maven by A LOT and the configuration possibilities are endless.
If it’s the performance aspect and you are basing on benchmarks posted by Gradle.org (a company btw) you should take those with serious reservations. For example I think the benchmarks don’t use -T.
Anyway we tested this on our projects and the difference was negligible granted we weren’t using gradles distributed cache build system.
What can you do in Gradle that you can’t in Maven?
I absolutely know there are things like not compile path separations and reproducible builds but I’m curious what your list is because Maven has some tricks of its own folks don’t know about it.
8
u/prince-banane Jan 17 '21
Things is you don't want a complex build. If you need Gradle instead of Maven, you should think why.
4
u/oweiler Jan 17 '21
If performance is a problem use https://github.com/mvndaemon/mvnd
2
u/pragmatick Jan 17 '21
Do you have any articles about the performance gain? I tried this a couple of weeks ago and it didn't really make a difference for me.
0
u/Yesterdave_ Jan 17 '21
This seems kinda inconvenient, or the documentation is not very clear. Now I have to rewrite every command in the pipeline and bash scripts to use "mvnd" instead of "mvn"? Is it even possible to use with IntelliJ at the moment, since I don't think IntelliJ would know that is should execute "mvnd" instead of "mvn"?
Gradle solution seems much easier as it is just a parameter in gradle.properties.
8
u/Dr-Metallius Jan 17 '21
I should say, despite being a Groovy developer, I use it everyday, that if you use IntelliJ IDEA in particular, discovering Gradle using the Kotlin DSL is much easier. You get smart, contextual, IDE completion, which really helps in understanding how Gradle works.
Now I'm going to cite this instead under each article which complains about Groovy in Gradle. Great article.
1
u/pjmlp Jan 17 '21
Basically give money to JetBrains in detriment of other Java developer stacks as means to be able to use Gradle.
That is indeed a good comment, that I can use for our Eclipse based customers to keep using Maven.
5
u/mauganra_it Jan 17 '21
That's a false dichotomy. I doubt that most people using Eclipse have ever donated even a single dime to the Eclipse foundation. If you did, kudos to you :)
9
u/Dr-Metallius Jan 17 '21 edited Jan 17 '21
I don't see how using convenient tools brings about negative changes in other tools. By the way, Intellij IDEA has a free edition. No one requires you to give money to anyone.
Since I don't use Eclipse, I don't know how convenient using Kotlin in Eclipse is, but I know it does have a Kotlin plugin. However, even if Kotlin isn't well-supported in Eclipse, how is this Gradle's fault?
4
u/pjmlp Jan 17 '21
If you are doing JEE in Eclipse, doing JEE in InteliJ requires the commercial license.
There is no Kotlin support in Eclipse, because again, JetBrains wants to sell InteliJ.
Personally I don't care about Kotlin outside Android anyway, it will be yet another JVM guest language, catching up with Java ecosystem.
3
u/Dr-Metallius Jan 17 '21
doing JEE in InteliJ requires the commercial license.
If you need inspections and suggestions, then yes, but you can still work without them like with regular projects. I've worked with Spring using the community edition, for example. If that doesn't suit you, but you still want to edit build files in IntelliJ IDEA, then use two IDEs: one for the project, another one for working with the build system.
There is no Kotlin support in Eclipse, because again, JetBrains wants to sell InteliJ.
Now you are saying things that are plainly untrue. Yes, there is a plugin, developed by no other than JetBrains themselves.
Personally I don't care about Kotlin outside Android anyway, it will be yet another JVM guest language, catching up with Java ecosystem.
I can see that you don't care about Kotlin, that's why you wouldn't know that Kotlin is within the same ecosystem as Java. Any code you write in Java can be used in Kotlin and vice-versa. Even annotation processors are universal. There is a reason why Kotlin is so popular, that's one of its biggest selling points.
4
u/pjmlp Jan 17 '21
From Kotlin developers themselves so that you don't keep up with the lies,
https://blog.jetbrains.com/kotlin/2011/08/why-jetbrains-needs-kotlin/
The next thing is also fairly straightforward: we expect Kotlin to drive the sales of IntelliJ IDEA. We’re working on a new language, but we do not plan to replace the entire ecosystem of libraries that have been built for the JVM. So you’re likely to keep using Spring and Hibernate, or other similar frameworks, in your projects built with Kotlin. And while the development tools for Kotlin itself are going to be free and open-source, the support for the enterprise development frameworks and tools will remain part of IntelliJ IDEA Ultimate, the commercial version of the IDE. And of course the framework support will be fully integrated with Kotlin.
https://kotlinlang.org/roadmap.html
Kotlin support for VSCode or other IDEs is not on the roadmap for the Kotlin team. Community initiatives in this respect are welcome.
Not caring about Kotlin, hoping that it goes down with Android when Fuchsia comes into full swing, doesn't mean I am clueless about it.
Have fun calling Kotlin co-routines from Java 15, using Java records, value types and future virtual threads, while keeping the code compatible with Android.
4
u/Dr-Metallius Jan 17 '21
From Kotlin developers themselves
I don't see any contradictions in the quote with what I said before.
doesn't mean I am clueless about it.
I'm only judging by what you wrote. If you write something that doesn't reflect the reality, the conclusion is obvious.
Have fun calling Kotlin co-routines from Java 15, using Java records, value types and future virtual threads, while keeping the code compatible with Android.
Using the Java ecosystem from Kotlin and keeping the code compatible with Android are two very different things. It's obvious that not everything written in Java can be used on Android, and Kotlin has nothing to do with that.
-7
u/pjmlp Jan 17 '21
Basically give money to JetBrains in detriment of other Java developer stacks as means to be able to use Gradle.
That is indeed a good comment, that I can use for our Eclipse based customers to keep using Maven.
1
u/franzwong Jan 18 '21
I am not familiar with Gradle. I tried it a few times and I went back to Maven. So what is the proper way to put execution script in Task? doFirst or doLast? Does do exist?
1
u/theblackavenger Jan 19 '21
At one point I made a groovy based system that generated maven POMs. Much less verbosity without turning it into a programming language. Gradle to me went down the wrong route. Making maven easier is imho much better than making a new build tool.
spullara/graven: Automatically exported from code.google.com/p/graven (github.com)
-3
Jan 17 '21
I like Gradle as a simpler Maven. Both build tools have little-to-no discoverability built in and don't make much logical sense so you just gotta memorize things. Except usually in Maven you have to memorize awkward XML hierarchies on top of everything else you gotta memorize.
You can of course use Gradle to do more than just build a project. And I like that aspect too - there's value there because so many IDEs integrate with Gradle so you can kinda use it as a cross platform scripting tool. But I view that role as different from building a project, and when I take advantage of it, like to keep it as segregated from the core build aspects as possible.
7
u/siimon04 Jan 17 '21
Gradle developer's reply to https://www.reddit.com/r/java/comments/ksf3ku/the_problem_with_gradle/