How do you set up a property in a custom gradle task?

Viewed 17

I want to write a task that takes a directory from , does something with the files in it and writes the result into some other directory to.

I've been led to believe this was the way to define such a task (kotlin dsl):

package my.app

abstract class FooBarTask : DefaultTask() {

    @get:InputDirectory
    abstract val from: Property<Directory>

    @get:OutputDirectory
    abstract val to: Property<Directory>

    @TaskAction
    fun doSomething() {
        println("Hakuna Matata")
    }
}

now how do I set the from and to value in a groovy-based build.gradle?

def myTask = tasks.register('myTask', FooBarTask) {
    from = layout.projectDirectory.dir("foo")
    to = layout.buildDirectory.dir("bar")
}

this results in

Could not create task ':my-subproject:myTask'.
   > Please use the ObjectFactory.directoryProperty() method to create a property of type Directory.

and it shouldn't.

How do you correctly define a directory property in a custom task?

0 Answers
Related