3

Add API for TaskProviders on tasks that possibly don't exist yet · Issue #16543...

 2 years ago
source link: https://github.com/gradle/gradle/issues/16543
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Comments

A common task ordering papercut I run into is the need to depend on a task that I know will exist, but doesn't exist at the time I register it.

val knownTestTask = "testReleaseUnitTest"
val dependentTask = project.tasks.register("dependent") {
  // ...
}

// Wait for the task that matches to appear in tasks, configure then
project.tasks.matching { it.name == knownTestTask }
  .configureEach { 
    val task = this
    dependentTask.configure {
      dependsOn(task)
    }
  }

This is a pain with ordering, and often a crash for unsuspecting plugin authors that try to use tasks.named(knownTestTask) only to be hit with an exception if it doesn't exist yet.

The worst case scenario is that an author may just punt it to an afterEvaluate {} block and hope for the best.

I'd like to propose a new API for a "future" task that returns a TaskProvider for a task that will eventually exist.

val knownTestTask = "testReleaseUnitTest"
val knownTestTaskProvider = project.tasks.futureNamed(knownTestTask)
val dependentTask = project.tasks.register("dependent") {
  // ...
  dependsOn(knownTestTaskProvider)
}

Naming suggestions definitely welcome!

Another consideration would be cases where the task never exists, which I think could be ok and just effectively a no-op. If it's mapped, it would just be an empty provider.

Another benefit of this is that it could allow reuse of the TaskProvider, whereas the current configureEach-based solution requires a new filter every time one wants to use it.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK