Skip to content

Commit e518d9f

Browse files
committed
Use Task Configuration Avoidance
Closes #36
1 parent 2662784 commit e518d9f

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Changelog
44
This changelog format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
Version 2.1.0 (2021-07-01)
8+
----------------------------
9+
* Use [Task Configuration Avoidance](https://docs.gradle.org/current/userguide/task_configuration_avoidance.html)
10+
711
Version 2.0.1 (2021-07-01)
812
----------------------------
913
* Upgrade `org.apache.commons:commons-lang3` due to vulnerability

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Gradle Task Tree
22

3-
[![version](https://img.shields.io/badge/version-2.0.1-orange.svg)](./CHANGELOG.md)
3+
[![version](https://img.shields.io/badge/version-2.1.0-orange.svg)](./CHANGELOG.md)
44

55
Gradle plugin that adds a `taskTree` task that prints task dependency tree report to the console.
66

@@ -16,7 +16,7 @@ The plugin is published on [Gradle Plugin Portal](https://plugins.gradle.org/plu
1616

1717
```groovy
1818
plugins {
19-
id "com.dorongold.task-tree" version "2.0.1"
19+
id "com.dorongold.task-tree" version "2.1.0"
2020
}
2121
```
2222

@@ -30,7 +30,7 @@ initscript {
3030
maven { url "https://plugins.gradle.org/m2" }
3131
}
3232
dependencies {
33-
classpath "gradle.plugin.com.dorongold.plugins:task-tree:2.0.1"
33+
classpath "com.dorongold.plugins:task-tree:2.1.0"
3434
}
3535
}
3636
rootProject {
@@ -115,7 +115,7 @@ To allow a sub-tree of the same task to be repeated more than once, add the comm
115115
For a more static custom configuration, you can put the following in `build.gradle` (or, in case you take the [init script approach](#init-script-snippet), in `init.gradle`).
116116
```groovy
117117
//optional configuration (per project)
118-
taskTree {
118+
tasks.named('taskTree').configure {
119119
depth = 3 // limit tree depth to 3. Equivalent to the --depth CLI task option.
120120
withInputs = true // prints task inputs in red just below the task in the tree. Equivalent to the --with-inputs CLI task option.
121121
withOutputs = true // prints task inputs in red just below the task in the tree. Equivalent to the --with-outputs CLI task option.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ java {
2727

2828

2929
group = 'com.dorongold.plugins'
30-
version = '2.0.1'
30+
version = '2.1.0'
3131
description = "Gradle plugin that adds a 'taskTree' task that prints task dependency tree"
3232

3333
//Building a text file that contains the classpath of the plugin code. needed for testing on gradle versions prior to 2.5

src/main/groovy/com/dorongold/gradle/tasktree/TaskTreePlugin.groovy

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.dorongold.gradle.tasktree
22

3-
43
import groovy.transform.TypeChecked
54

65
import org.gradle.api.Plugin
@@ -26,27 +25,26 @@ class TaskTreePlugin implements Plugin<Project> {
2625

2726

2827
void apply(Project project) {
29-
project.allprojects { Project rootOrSubProject ->
30-
if (rootOrSubProject.tasks.findByName(TASK_TREE_TASK_NAME)) {
31-
// Skip if this sub-project already has our task. This can happen for example if the plugin is applied on allProjects.
32-
return
33-
}
34-
validateGradleVersion()
35-
rootOrSubProject.tasks.register(TASK_TREE_TASK_NAME, TaskTreeTask)
36-
37-
rootOrSubProject.gradle.taskGraph.whenReady {
38-
if (project.gradle.taskGraph.allTasks.any { Task task -> task.class in TaskTreeTaskBase }) {
39-
rootOrSubProject.tasks.configureEach { Task task ->
40-
if (!(task in TaskTreeTaskBase)) {
41-
task.setEnabled(false)
42-
}
28+
validateGradleVersion()
29+
30+
project.subprojects { Project subproject ->
31+
subproject.pluginManager.apply(TaskTreePlugin)
32+
}
33+
34+
project.tasks.register(TASK_TREE_TASK_NAME, TaskTreeTask)
35+
36+
project.gradle.taskGraph.whenReady {
37+
if (project.gradle.taskGraph.allTasks.any { Task task -> task.class in TaskTreeTaskBase }) {
38+
project.tasks.configureEach { Task task ->
39+
if (!(task in TaskTreeTaskBase)) {
40+
task.setEnabled(false)
4341
}
4442
}
4543
}
4644
}
4745
}
4846

49-
private void validateGradleVersion() {
47+
private static void validateGradleVersion() {
5048
if (GradleVersion.current() < GradleVersion.version(GRADLE_MINIMUM_SUPPORTED_VERSION)) {
5149
throw new UnsupportedVersionException(UNSUPPORTED_GRADLE_VERSION_MESSAGE)
5250
}

0 commit comments

Comments
 (0)