This message was deleted.
# community-support
s
This message was deleted.
c
Real question, what does WorkerExecutor buy you in this task?
You'd want inputs and outputs for incremental build support
e
workers allow for controlled parallel execution
c
As in running gradle with --parallel?
e
the left-hand side is wrong anyway since that runs at configuration time
c
right it'd need at least a doLast or something
t
Yep, other tasks could run in parallel, as long as they don't need the outputs of this task. https://docs.gradle.org/current/userguide/custom_tasks.html#worker_api:~:text=Once%20all%20of,begin%20executing%20immediately.
v
But that has nothing to do with
--parallel
, that is just for running tasks from different decoupled projects in parallel. The worker api parallelity is always on unless maybe you restrict it with
--max-workers
.
x
right,
--parallel
is about running tasks from different projects in parallel. the worker API is about running tasks from the same project to run at the same time. The need of the worker API will be reduced quite a bit with configuration caching (it will only be useful when you want to run several workers for a single task)
m
Reminds me of this idea of having an IDL which generates all the boilerplate for you...
v
The need of the worker API will be reduced quite a bit with configuration caching (it will only be useful when you want to run several workers for a single task)
Probably, yeah. But most people probably don't use the worker api for each and every tiny thing anyway, but only if they do long-running things or parallelizable tasks on multiple files.
βž• 1
m
Agreed most tasks don't need the worker API
e
using it to write a string to a file as in this example is complete overkill, I think we all agree
x
Right. In the android plugin we have a lot of usages of the worker APIs mostly for single worker tasks. I'm looking forward to simplifying them (Jake has a point on this, it's quite painful). We also do have a lot of simpler tasks where we don't use it because it's not worth it
m
the tweet is funny nonetheless. Another funny thing is that basically the initial version is what Maven does. It doesn't f* care about any input/output/incrementalism so it's much simpler to write.
x
Sadly, there are quite a few people who don't care and just want to write the left part only πŸ˜•
m
Gradle only makes it more complex because it has higher modeling, which makes it inherently better. Not easier for plugin authors, but better πŸ™‚
x
Yes, except that it's not just "plugin authors". We see a lot of random users who don't understand anything try to make a custom task for one tiny feature they need, and they most definitively do the left side, because they don't know better (And in most cases don't want to have to learn mode).
v
It's totally ok to write the left part (if it is fixed to use
doLast
or
doFirst
) as long as you don't care about performance and correctness and anyway inherited the habit to always call the
clean
task along. πŸ™‚
πŸ‘ 1
x
I wish Gradle both made it impossible to do the left side (so that you don't shoot yourself in the foot), and made it easier to do the right side
βž• 2
m
I spent a couple hours today showing a colleague of mine how to move from a left "spike" in a build script to a proper plugin (right, but without worker API). He was baffled how clean the final solution was πŸ™‚
x
It's totally ok to write the left part (if it is fixed to use
doLast
or
doFirst
) as long as you don't care about performance and correctness and anyway inherited the habit to always call the
clean
task along. πŸ™‚
but then they come back to us (and Gradle) and complain their builds are slow...
πŸ˜‚ 1
m
the right side is already much easier than it used to be. Automatic code generation for
Property<String>
is a huge win.
βž• 1
v
Then that's the point where they have enough motivation to do it the right way πŸ˜„
x
Sadly the current narrative is "Gradle is slow", not "my random customizations" (or "my compilers", looking at you Kotlin...) are slow.
m
you forgot "I hate build tools" πŸ™‚
πŸ˜„ 2
e
all build tools suck, gradle just sucks less at several ways I care about
v
Kotlin is not slow. It is a bit slower than Groovy in some cases and it is a bit faster than Groovy in other cases. (and yes, I'm talking about Gradle build scripts, not about the languages in general)
But yeah, you will always have people call something slow because they don't use it properly.
Same with Java, there are also still people saying "Java is slow" which is non-sense.
m
Kotlin compilation is order of magnitudes slower than Groovy. Fun fact: when I joined Gradle, my first task was to optimize Groovy scripts compile times. It became blazing fast. Then we had Kotlin DSL and it was like 10x slower but nobody cared (almost). Sad.
x
The Kotlin compiler is slow (work is being done to fix it, though it'll never be as fast as javac). Now regarding KTS, I have a project where groovy script compilation takes 90s and the same version with KTS takes 10min. (this is with ~3,400 build files)
v
o_O
This is what I have in mind:
e
parallel script compilation would be nice, someday…
x
yeah Paul told that to me then I did the test and was a bit shocked. I'm going to send them the projects for them to play with them
πŸ™ 1
v
Yes, please do πŸ™‚
Also, when configuration caching is stable and widely adopted, we have 0 time anyway hopefully πŸ˜„
x
until you edit a build file, but otherwise yes πŸ™‚
v
Hopefully most time you edit code, not build and even if you edit a build file hopefully only that one is recompiled and not all 3400 that are unchanged πŸ™‚
x
right but then you still need to rebuild the task graph and that's slow too πŸ™‚
but dont get me wrong, I'm very excited by config caching. There's just room for more improvements
v
Always πŸ™‚
e
every large build system has that problem. google3 blaze bazel already had to deal with the full task graph being too large to fit into memory years ago, iirc
c
@melix wrt code generation for Property<String>, does that mean its better to use abstract inputs/outputs? Would you provide defaults in the constructor then?
v
Actually, I learned that in an idiomatic structure, the extensions and tasks should be unopinionated and thus do not have default values, and the according plugin that registers specific tasks adds opinion by wiring together extension and task properties and setting default values.
c
Ah so drop all the defaults in the tasks.register block?
v
For example, yes
j
for tasks that usually are only created once per project, i will sometimes put a companion object in the Task class (kotlin) with a JvmStatic method that takes a project, and registers the task, then applies all the default opinions, just to make the plugin code simpler for the default case. and then you can always just register the task the regular way if you want one with no opinions
you could do a similar thing with a static method in groovy/java
that kind of spiritually aligns with the "use static methods instead of public constructors" advice from effective Java without sacrificing the idiom of not hard-coding opinions on tasks/extensions