22

Probably a simple question but I can't find a way to list which tasks are introduced by the plugins that get applied in a build.gradle file. So, say that your build.gradle is simply:

apply plugin: 'java'

is there a simple way to make gradle list all the tasks introduced by that plugin?

PS: that would come handy in case of messy and large build files with dozens of applied plugins

PS2: I'm not asking about the dependencies of the tasks. My question is different and quite clear. Each plugin that I apply introduces some tasks of its own (never mind what depends on what). The question is which are the newly introduced tasks in the first place?

  • Possible duplicate of [Is there a way to list task dependencies in Gradle?](http://stackoverflow.com/questions/10422054/is-there-a-way-to-list-task-dependencies-in-gradle) – LeslieV Apr 28 '16 at 20:44
  • My question is different. Read PS2. –  Apr 29 '16 at 07:01
  • 1
    Not a really nice way but you could try to diff `./gradlew tasks --all` results – with and without the plugin. – alexvetter Apr 29 '16 at 07:04
  • Not that bad for small(ish) projects but still awkward and not scalable :( –  Apr 29 '16 at 07:20
  • Another way would be to look at the source of the plugin. :-D – alexvetter Apr 29 '16 at 07:29
  • 1
    Yup. And its documentation (provided there is any). That's what I've been doing actually. Yet it would be handy if there was a gradle command to list each plugin's tasks. –  Apr 29 '16 at 07:33

3 Answers3

19

I'm afraid it is not possible because of the nature how gradle plugins are applied.

If you take a look at Plugin interface, you will see it has a single apply(Project p) method. Plugin responsibility is to configure a project - it can add specific tasks / configurations / etc. For example, gradle JavaPlugin is stateless, so you can't get tasks from it.

The only solution that comes to mind is to get a difference of tasks after the plugin is applied:

build.gradle

def tasksBefore = [], tasksAfter = []    
project.tasks.each { tasksBefore.add(it.name) } // get all tasks

apply(plugin: 'idea') // apply plugin

project.tasks.each { tasksAfter.add(it.name) } // get all tasks
tasksAfter.removeAll(tasksBefore); // get the difference

println 'idea tasks: ' + tasksAfter;

This will print tasks that were added by Idea plugin:

idea tasks: [cleanIdea, cleanIdeaModule, cleanIdeaProject, cleanIdeaWorkspace, idea, ideaModule, ideaProject, ideaWorkspace]

You can play a bit with this code and build an acceptable solution.

AdamSkywalker
  • 11,408
  • 3
  • 38
  • 76
1

In some cases origin from specific plugin can be restored by checking the task's group and name:

tasks.findAll { it.group == 'verification' && it.name.startsWith('jacoco') }.each { task ->
    println(task.name)
}
Vadzim
  • 24,954
  • 11
  • 143
  • 151
0

Just to compliment AdamSkywalkers answer, here's similar code for use in build.gradle.kts:

var tasksBefore = mutableSetOf<org.gradle.api.Task>()
project.tasks.forEach {
    tasksBefore.add(it)
}
apply (plugin = "idea")
var tasksAfter = mutableSetOf<org.gradle.api.Task>()
project.tasks.forEach {
tasksAfter.add(it)
}
tasksAfter.removeAll(tasksBefore) // get the difference

println ("idea tasks: " + tasksAfter)
Tom Rutchik
  • 1,183
  • 1
  • 12
  • 15