5 ms·
> Scoping is mysterious It definitely is confusing, but while the rules to scoping are pretty extensive, they're also well defined. The trick is to know how Gr
by wasyl 6y ago
> Scoping is mysterious
It definitely is confusing, but while the rules to scoping are pretty extensive, they're also well defined. The trick is to know how Gradle "travels" through objects and looks for the property in class properties, extensions, extras, etc. I wrote about it [1] if you're interested.
> Gradle script is interacting with things you can't see
Not necessarily -- yes, the receiver for top-level calls (Project instance) is implicit, but you can access it via `project` property. You could prefix each top-level call in your Gradle script with `project.`, making all calls explicit.
Btw `sourceSets { }` calls the lambda on a `SourceSetContainer` instance, accessible via `Project#sourceSets` property [2], so you can get an instance of it. I suppose there might some objects that are configurable but not accessible, but nothing comes to my mind right away, actually.
> a build tool is a thing that tracks dependencies so that it only has to rebuild things whose inputs have changed. Gradle doesn't do that at all.
You might've had a bad experience with a misconfigured plugin/build or a bug. Gradle does track dependencies, and while it doesn't do that perfectly always, it avoids a lot of unnecessary work, on many layers (incremental compilation, task avoidance, task caching). As a general rule, when running the same task(s) twice, the second invocation shouldn't execute any taks.
> This is because the entire dependency graph is constructed dynamically on every run
It's true that configuration/task graph creation is still happening on every invocation (this will change with Configuration Cache [3]). But it's definitely not accurate that this prevents Gradle from knowing which steps have already been done. Again, I fully believe it didn't work for you, but it doesn't mean Gradle doesn't do that.
I'm not trying to say Gradle doesn't have flaws. In fact, I think your comment proves the points from the article. Unless one invests in learning how Gradle works, it's impossible to spot e.g. why the build isn't doing any task avoidance, or understand scoping. It's rather unfortunate, because after that initial investment Gradle is a pretty great tool to work with.
[1] https://medium.com/tooploox/where-do-gradle-properties-come-from-bf77e43ee572 https://medium.com/tooploox/where-do-gradle-properties-come-...
[2] https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project:sourceSets https://docs.gradle.org/current/dsl/org.gradle.api.Project.h...
[3] https://docs.gradle.org/current/userguide/configuration_cache.html https://docs.gradle.org/current/userguide/configuration_cach...
- oblio 6y agoThat initial investment is non-trivial, though. It's at least tens of hours of study in my experience. And they keep adding concepts and deprecating old ones. And keep in mind this is just for the build tool, someone using Gradle probably already has to juggle a million other details, most likely much more important than Gradle (business concerns, main tech stack concerns, etc.). Gradle is practically consultingware.
- p2detar 6y agoIs there really a tool that’s flawless? Btw, when was the last time you used Gradle? For what type of projects and are you currently using it in prod?
- oblio 6y agoI last used it about 1 year ago, Java web app, in prod.
- lmm 6y ago> Is there really a tool that’s flawless? Yes. Maven.
- p2detar 6y agoFunny. Maven was the reason I went to Gradle. :)
- blandflakes 6y agoI prefer maven but it most certainly does not feel flawless to me.