From 7a04f861fac9ba5ca779d4f0279f4d0208ad0467 Mon Sep 17 00:00:00 2001 From: Svyatoslav Chatchenko Date: Wed, 15 Jul 2020 22:30:23 +0200 Subject: [PATCH] Use lazy task configuration for dependencyUpdates Instead of configuring the task using the instance of it, use "named" function that returns TaskProvider. Kotlin sample before changes: https://scans.gradle.com/s/agejecharcfa6/performance/configuration?focused=5&openScriptsAndPlugins=WzBd Kotlin sample after changes: https://scans.gradle.com/s/mxv25ulispr4w/performance/configuration Groovy sample before changes: https://scans.gradle.com/s/szcsxpdg6tfzu/performance/configuration?focused=5&openScriptsAndPlugins=WzBd Groovy sample after changes: https://scans.gradle.com/s/xwxm6zqwivgew/performance/configuration --- README.md | 14 ++++++-------- examples/groovy/build.gradle | 2 +- examples/kotlin/build.gradle.kts | 4 +--- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5a0f7d1e..a91c142c 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ initscript { allprojects { apply plugin: com.github.benmanes.gradle.versions.VersionsPlugin - dependencyUpdates { + tasks.named("dependencyUpdates").configure { // configure the task, for example wrt. resolution strategies } } @@ -151,7 +151,7 @@ You can either use the simplified syntax `rejectVersionIf { ... }` or configure ```groovy -dependencyUpdates { +tasks.named("dependencyUpdates").configure { // Example 1: reject all non stable versions rejectVersionIf { isNonStable(it.candidate.version) @@ -184,7 +184,7 @@ dependencyUpdates { ```kotlin import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask -tasks.withType { +tasks.named("dependencyUpdates", DependencyUpdatesTask::class.java).configure { // Example 1: reject all non stable versions rejectVersionIf { isNonStable(candidate.version) @@ -232,10 +232,8 @@ transitive dependency versions, you can enable checking of constraints by specif attribute of the `dependencyUpdates` task. ```groovy -tasks { - dependencyUpdates { +tasks.named("dependencyUpdates").configure { checkConstraints = true - } } ``` @@ -246,7 +244,7 @@ If using Gradle's [kotlin-dsl][kotlin_dsl], you could configure the `dependencyU ```kotlin import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask -tasks.withType { +tasks.named("dependencyUpdates", DependencyUpdatesTask::class.java).configure { // optional parameters checkForGradleUpdate = true @@ -558,7 +556,7 @@ For example, if you wanted to create an html table for the upgradable dependenci ```groovy ... -dependencyUpdates { +tasks.named("dependencyUpdates").configure { outputFormatter = { result -> def updatable = result.outdated.dependencies if (!updatable.isEmpty()){ diff --git a/examples/groovy/build.gradle b/examples/groovy/build.gradle index b5c3976a..6a58dc15 100644 --- a/examples/groovy/build.gradle +++ b/examples/groovy/build.gradle @@ -36,7 +36,7 @@ def isNonStable = { String version -> return !stableKeyword && !(version ==~ regex) } -dependencyUpdates { +tasks.named("dependencyUpdates").configure { checkForGradleUpdate = true // Example 1: reject all non stable versions diff --git a/examples/kotlin/build.gradle.kts b/examples/kotlin/build.gradle.kts index a1668e06..80831e1d 100644 --- a/examples/kotlin/build.gradle.kts +++ b/examples/kotlin/build.gradle.kts @@ -36,9 +36,7 @@ fun isNonStable(version: String): Boolean { return isStable.not() } - - -tasks.withType { +tasks.named("dependencyUpdates", DependencyUpdatesTask::class.java).configure { // Example 1: reject all non stable versions rejectVersionIf {