This message was deleted.
# community-support
s
This message was deleted.
j
If I remember correctly, calling named was being affected by the order of task registration, which looks like this new named is fixing.
e
no, it's to replace
tasks.matching { predicate(it.name) }
with
tasks.named { predicate(it) }
named(String)
still has the same behavior as always
j
That implementation is not fixing this?
Copy code
tasks.named("foo")
tasks.register("foo")
Copy code
Task with name 'foo' not found in root project 'gradle-extensions-project'.
What would be the behavior of
Copy code
// find `foo`? or this would be an empty list?
tasks.named { it == "foo" }.configureEach { ... } 
tasks.register("foo")
e
1. no, that's intentional and not to be fixed. if you use
named(String)
you expect a task to be registered already. 2. it's a live collection so the closure will be executed after the registration, same as
matching
j
1. That is really annoying, that task can be registered by another plugin or other configuration, creating a mental problem which is: "I need a
maybeCreate
which works lazily so I don't need to worry about".
e
maybeCreate
is also (almost always) the wrong solution too
j
Because it is not lazy, if not, which would the problem be?
e
just react to the plugin
j
That is the main problem, which plugin? You can't react to all plugins.
e
if more than one plugin is registering the same task then you have an issue, full stop
j
What could I do if the plugin is not doing the right things?
I cannot react to that plugin being applied on all projects because it is not being applied on all projects, and if I call
named
, it fails. The only solution is
afterEvaluate
?
withType<Task>().matching { ... }
would not help here
e
you can react to plugins applied to the root project, or you could fix their plugin by (if they insist on poking into subprojects) applying a sub-plugin instead of doing that directly
why doesn't
matching
help?
j
is not calling
withType<Task>
with
Task
a bad practice?
you could fix their plugin
They already have a branch fixing a lot those things for months, I am not sure when they will merge it
e
no,
withType()
is fine.
withType {}
is not.
.matching().configureEach {}
is not quite ideal, but that's what
.named(Spec)
fixes
j
I am not going to call
configureEach
in this case. I am creating another task which will depends on this task
Is this a problem
tasks.withType<Task>().named("apiCheck")
and should I use
matching
?
I guess until they merge the new one, it is
e
if you want to react to task registration, you have to break configuration avoidance one way or another
(or poke at internal apis)
j
I have no other way, registering those tasks with
allprojects
implies breaking calling
named
on subprojects without using
afterEvaluate
or
matching
. I would keep one of them as a workaround until the PR is merged