This message was deleted.
# community-support
s
This message was deleted.
j
I am on mobile but what about getting the task collection and pass it to the depends on instead of nesting?
g
You could collect task names for all signing tasks if they have some kind of regular names (using
tasks.names.filter { .. }
) and then use
tasks.withType<AbstractPublishToMaven>().configureEach { dependsOn(signTaskList) }
Another way is to register dummy task, have it depend on all signing tasks and make all publish to maven tasks depend on it
That is if I understood correctly what you do want in this case of course
j
Copy code
public inline fun <reified T : Task> TaskContainer.namedLazily(
    name: String,
    action: Action<in T>? = null,
): TaskCollection<T> {
    val collection: TaskCollection<T> = withType<T>().matching { it.name == name }
    if (action != null) collection.configureEach(action)
    return collection
}
this should be lazy, but you shouldn't need the matching part because you want all tasks that withType returns
e
@Javi how would I get all the publishing tasks?
g
@Javi, aren't tasks realized on calling
matching
? I surely hope not but am not sure about it.
j
val publishingTasks = tasks.withType<Publish>()
🙈 1
e
So far I have:
Copy code
val signingTasks = tasks.withType<Sign>()
tasks.withType<AbstractPublishToMaven>().configureEach {
  dependsOn(signingTasks)
}
which at least doesn't have any errors with a dry run. Now to actually test it.
g
iirc all publish task registered by maven-publish plugin have regular names so you could match them using simple regex. They had names like
publish(PublicationName)To(RepositoryName)Repository
j
Interested on your results, share here please :)
e
@grossws I originally had something like that where I iterated through the targets and built the task names from their publications but it was getting long and more complicated than I wanted
j
In my case for maven I am using nexus publish plugin so I have publishToSonatype task too
g
So matching is eager as I remember. But
tasks.withType<T>().matching { .. }
would only realize tasks of type
T
as expected.
e
Looks like
Copy code
val signingTasks = tasks.withType<Sign>()
tasks.withType<AbstractPublishToMaven>().configureEach {
  dependsOn(signingTasks)
}
did the trick 😄
👍 2
v
Yes, that's the very first suggestion of Javi :-)
@grossws exactly. That's why you usually should prefer an
if
in the configuration block if you don't need the actual collection, but want to configure depending on name. :-)