I’m trying to define a custom Gradle task in a Grails project.
Here’s the task implementation
MyCustomTask.groovy
package my.project
import my.project.stuff.DoSomething
import org.gradle.api.DefaultTask
class MyCustomTask extends DefaultTask {
@TaskAction
void execute() {
DoSomething.do() // willing to re-use code already in place and working
}
}
Then I register the task in build.gradle
build.gradle
[...]
project.tasks.register(MyCustomTask, 'exec') {
group = 'Custom tasks'
}
But then when I reload Gradle setting for my project, I get this error:
A problem occurred evaluating root project ‘myProject’.
Could not get unknown property ‘MyCustomTask’ for root project ‘myProject’ of type org.gradle.api.Project.
Gradle documentation about implementing custom tasks shows as example the structure of a “Java application with the source code in the app
subproject and the common build logic in buildSrc
“.
The project I’m working on has no subproject. Is there a way I can make this task being loaded with no error?
Thanks in advance!