Tag Archives: Groovy Scripts

Gradle Goodness: Running Groovy Scripts as Application

Gradle Goodness: Running Groovy Scripts as Application

gradle-logoIn a previous post we learned how to run a Java application in a Gradle project. The Java source file with a main method is part of the project and we use the JavaExectask to run the Java code. We can use the same JavaExec task to run a Groovy script file.

A Groovy script file doesn’t have an explicit main method, but it is added when we compile the script file. The name of the script file is also the name of the generated class, so we use that name for the main property of the JavaExec task. Let’s first create simple Groovy script file to display the current date. We can pass an extra argument with the date format we wan’t to use.