Is there a proper way to create a task for each so...
# plugin-development
j
Is there a proper way to create a task for each source set, without using afterEvaluate? I want to make sure it is created even if the plugin that creates the source set is applied after mine...
t
in pseudcode
Copy code
sourceSets.configureEach { s ->
  project.tasks.register("myCoolTask${s.name}") {
    ...
  }
}
j
ahh ok that makes sense. thanks!
πŸ‘ 1
p
(Until now) sourceSets are not lazy, so you are safe to call
all
too. And I don’t think they will be ever lazy
πŸ‘ŽπŸΎ 1
t
it's good practice to use configureEach universally. I used to think that Configurations would always be eager, but a recent Gradle release made them lazy. So now I have to go back and change all my `all`s to `configureEach`s. You never know and it doesn't hurt
πŸ‘ 2
πŸ˜… 1
βž• 1
πŸ‘πŸΎ 1
j
As additional note: There is also
getTaskName
for a source set specific task name in the structure the core plugins name source-set-specific tasks. E.g.:
register(getTaskName("generate", "ExampleCode")) ...