Skip to content

Commit

Permalink
Use Task Configuration Avoidance
Browse files Browse the repository at this point in the history
Closes #36
  • Loading branch information
dorongold committed Jul 1, 2021
1 parent 2662784 commit e518d9f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
This changelog format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

Version 2.1.0 (2021-07-01)
----------------------------
* Use [Task Configuration Avoidance](https://docs.gradle.org/current/userguide/task_configuration_avoidance.html)

Version 2.0.1 (2021-07-01)
----------------------------
* Upgrade `org.apache.commons:commons-lang3` due to vulnerability
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gradle Task Tree

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

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

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

```groovy
plugins {
id "com.dorongold.task-tree" version "2.0.1"
id "com.dorongold.task-tree" version "2.1.0"
}
```

Expand All @@ -30,7 +30,7 @@ initscript {
maven { url "https://plugins.gradle.org/m2" }
}
dependencies {
classpath "gradle.plugin.com.dorongold.plugins:task-tree:2.0.1"
classpath "com.dorongold.plugins:task-tree:2.1.0"
}
}
rootProject {
Expand Down Expand Up @@ -115,7 +115,7 @@ To allow a sub-tree of the same task to be repeated more than once, add the comm
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`).
```groovy
//optional configuration (per project)
taskTree {
tasks.named('taskTree').configure {
depth = 3 // limit tree depth to 3. Equivalent to the --depth CLI task option.
withInputs = true // prints task inputs in red just below the task in the tree. Equivalent to the --with-inputs CLI task option.
withOutputs = true // prints task inputs in red just below the task in the tree. Equivalent to the --with-outputs CLI task option.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ java {


group = 'com.dorongold.plugins'
version = '2.0.1'
version = '2.1.0'
description = "Gradle plugin that adds a 'taskTree' task that prints task dependency tree"

//Building a text file that contains the classpath of the plugin code. needed for testing on gradle versions prior to 2.5
Expand Down
30 changes: 14 additions & 16 deletions src/main/groovy/com/dorongold/gradle/tasktree/TaskTreePlugin.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.dorongold.gradle.tasktree


import groovy.transform.TypeChecked

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


void apply(Project project) {
project.allprojects { Project rootOrSubProject ->
if (rootOrSubProject.tasks.findByName(TASK_TREE_TASK_NAME)) {
// Skip if this sub-project already has our task. This can happen for example if the plugin is applied on allProjects.
return
}
validateGradleVersion()
rootOrSubProject.tasks.register(TASK_TREE_TASK_NAME, TaskTreeTask)

rootOrSubProject.gradle.taskGraph.whenReady {
if (project.gradle.taskGraph.allTasks.any { Task task -> task.class in TaskTreeTaskBase }) {
rootOrSubProject.tasks.configureEach { Task task ->
if (!(task in TaskTreeTaskBase)) {
task.setEnabled(false)
}
validateGradleVersion()

project.subprojects { Project subproject ->
subproject.pluginManager.apply(TaskTreePlugin)
}

project.tasks.register(TASK_TREE_TASK_NAME, TaskTreeTask)

project.gradle.taskGraph.whenReady {
if (project.gradle.taskGraph.allTasks.any { Task task -> task.class in TaskTreeTaskBase }) {
project.tasks.configureEach { Task task ->
if (!(task in TaskTreeTaskBase)) {
task.setEnabled(false)
}
}
}
}
}

private void validateGradleVersion() {
private static void validateGradleVersion() {
if (GradleVersion.current() < GradleVersion.version(GRADLE_MINIMUM_SUPPORTED_VERSION)) {
throw new UnsupportedVersionException(UNSUPPORTED_GRADLE_VERSION_MESSAGE)
}
Expand Down

0 comments on commit e518d9f

Please sign in to comment.