Run Gradle tasks from Grails 3 custom scripts
In Grails 3 each script extends from GroovyScriptCommand. One of the property which GroovyScriptCommand provides is “gradle”. With the help of this property you can invoke gradle tasks.
When you write :
[java]
grails create-scipt demo
[/java]
A script file will be generated in src/main/scripts folder with the name demo.groovy
Now let us assume that there is a custom task in build.gradle:
[java]
task hello {
doLast { println "This is my task" }
}
[/java]
and we want to execute this Gradle task inside our custom Grails script.
We can simply do it by using the following statement in
demo.groovy
[java]
gradle.hello()
[/java]
Now if we run the grails custom script:
[java]
grails demo
[/java]
It will run the hello task inside build.gradle