How to create custom tasks to be executed in custom plugin

(Sage Smith) #1

I am trying to create a custom plugin that will execute a custom task based on a custom extension. The custom task is created by the plugin, but it is never executed.

Here is my build.gradle:

apply plugin: FooPlugin

def info1 = "loc1"
def info2 = "loc2"

foos {
    fee {
        info = info1
    fie {
        info = info2

Here is my plugin:

class FooPlugin implements Plugin<Project> {
    void apply(Project project) {
        def foos = project.container(Foo)
        project.extensions.foos = foos
            project.tasks.create(, FooTask.class)
            println project.tasks.getByName(

The output of this println is:

task ':fee'
task ':fie'

Here is my task:

 class FooTask extends DefaultTask{
    def doStuff() {
        println "here"
        println project.extensions

Two tasks of the type FooTask are created however here and the project extensions are never printed

Here is my extension:

 class Foo{
    final String name

    Foo(String name) { = name

    Collection<String> options = []

    boolean recursive = true

    File source

    File target