Book Image

Mastering Gradle

Book Image

Mastering Gradle

Overview of this book

Table of Contents (17 chapters)
Mastering Gradle
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Groovy script for Hello World


We have discussed what Groovy is and some of its important features. Let us create a Hello World program and feel the magic with Groovy. Here we are assuming that Groovy is installed on the system, GROOVY_HOME is pointing to the installation directory and <GROOVY_HOME>/bin has been added to the PATH environment variable:

file: GroovyTest.groovy
  println "Hello Groovy"

And that's all. Yes, for a simple Groovy program, you don't need to declare any packaging, any main class, or any semicolons, only a simple println statement would create your first Groovy program.

To execute the program, use the following command:

$ groovy GroovyTest.groovy
  Hello Groovy

The groovy command is used to execute the Groovy script. The beauty of the Groovy script is that it can execute any file, not only files with the .groovy extension. Even you can write the preceding println statement in the Test.text file and use the groovy command to execute the file. File extension doesn...