question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gradle: use new lazy tasks API when supported (Gradle 4.9+)

See original GitHub issue

See https://docs.gradle.org/current/userguide/task_configuration_avoidance.html

This boils down to:

  • using project.tasks.register instead of project.tasks.create
  • moving call to project.afterEvaluate and dependsOn outside the configuration closure, and to act on the task (in project.afterEvaluate), use task.configure { … } as task would then actually be a TaskProvider.
  • using configureEach instead of all
  • using project.tasks.named(…).configure { … } instead of project.tasks[…].…

This can generally be done quite easily with a couple utility functions using version checks.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tbroyercommented, Sep 4, 2018

Do you have a patch of one of your own plugins migrating to new APIs (including if/ten/else to support older versions)? I can look into it next weekend.

The simplest is https://github.com/tbroyer/gradle-errorprone-plugin/commit/eb0f35b32b81a8f9d28f4b1aa790bac4b371b704 but only covers configureEach vs. all. https://github.com/tbroyer/gradle-errorprone-javacplugin-plugin/commit/e795a20cc1ef77f35ef3baf7c8d509f5546f3310 uses Kotlin extension methods; and finally I have https://github.com/tbroyer/gradle-apt-plugin/commit/5e8b10f76d13584ed54f183c771fbd10ec3036a0 and https://github.com/tbroyer/gradle-apt-plugin/commit/432509ec85d1ab49296d4f9b21fad876523c6a8a that delegate to one of many implementations depending on the Gradle version. HTH

1reaction
tbroyercommented, Sep 4, 2018

Fwiw, the plugin could also use lazy configuration instead of conventionMapping, though that would mean bumping the minimum supported Gradle version to 4.3 (or maybe even 4.4). See https://docs.gradle.org/current/userguide/lazy_configuration.html

And wrt the lazy tasks API, I haven’t had any issue moving to that in my own plugins and builds; you of course have to be cautious and only do in the configure closures what cannot be done with a TaskProvider (hence moving forbiddenTask.dependsOn(task) outside the closure, to be resolved when forbiddenTask is realized, not the task)

I understand you’d rather do a release before making those changes though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gradle 4.9-rc-1 Release Notes
The Gradle team is pleased to announce Gradle 4.9. First and foremost, this version of Gradle features experimental new lazy task API.
Read more >
Kotlin Gradle Plugin: Use new Gradle API for Lazy tasks
This API allows minimizing amount of tasks created on each build or task invocation. It's especially important for big multimodule projects because each...
Read more >
Butterknife plugin doesn't use lazy task APIs of gradle 4.9+
Butterknife doesn't use the new APIs and trigger the creation of most of tasks for most variants. I believe the only thing to...
Read more >
Upgrading your build from Gradle 4.x to 5.0 - API Manual
Maven 3 only supports unique snapshots, so we decided to remove them. Tasks & properties. The following legacy classes and methods related to...
Read more >
Grolifant : A Library to Support Gradle Plugin Development
ysb33r.grolifant.api . The reason for this is that in future the package will be used to indicate a level compatibility. For instance if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found