One of the first questions I face when I start playing with a new language, is about how to set a project using this language so that I can build and package my code. While learning how to do this with Groovy I ended up putting together a starter project that has a reusable build script and runner class that allows me to quickly get a new Groovy project up and running.
Groovy Quick Start is meant to help developers new to groovy to get started by providing a way to have a groovy project up and running with a minimum effort. It provides a default layout and a reusable gant script that knows how to compile, test and package your project out of the box.
Compiling your project
prompt> gant compile
This target knows how to compile any source files that are available in the default source location. If you execute this target out of the box should report the succesful creation of the required build output folders and the compilation of one sample java class and two sample groovy classes
Testing your project
prompt> gant test
The test target will compile the source code in the src and test_src folders, and then it will execute the unit tests located in the tests_src folder. When you run this target out of the box it will succesfully report the execution of two sample test classes
Preparing to distribute your project
prompt> gant distro
the distro target will create a distribution folder in your build_output folder. This dist folder will contain a lib folder with all the jars from the project lib folder, as well as the contents of the src folder packaged as a jar. Also in the dist folder is your README.txt file and a bin folder that contains the sample batch file provided with the project. To test the distribution you can cd into your
%path%\groovyquickstart\build_output\dist\bin and run the file "run.bat". This launch script will print the help message:
usage: runner [option]
"-h" help Print out this message containing help.
"-n" name <name to greet> The name of the user to be greeted.
"-r" run Runs some target.
"-v" version Print version information.
To test the sample commands in the Runner class, enter the command "run -n "foo" -r" This will return the output:
prompt> Hello from the starter class foo
This sample Runner class demonstrates how to use the CLI builder to read parameters from the command line and to execute a class in the project, based on those parameters.
Packaging your project
prompt> gant package
This target will create a zip file with the content of your dist folder in the
When you use the default folders for your project artifacts the gant script should work without modifications, If you feel that you need to add or improve your build steps just modify the gant build script to suit your needs.
The GroovyQuickStart can be imported into Eclipse, once you use the Eclipse import facilities you will need to update the project build dependencies to point to the correct location of the Groovy libraries.
For more information review the readme file located in the "groovyquickstart\docs" folder
I hope you can take advantage of Groovy Quick Start Project to get started on your groovy project and please feel free to contact me with any questions at firstname.lastname@example.org
An example 'run' script to test the distribution: run
Use that instead of the 'run.bat' that comes packaged in the groovyquickstart.zip .
It appears the original blog/site went down, the zip file is now attached: groovyquickstart.zip
My blog was out of comission for a while , but I am working on updating this project to use the new joint compiler, in the meantime here is a new zip file containing the run file for linux groovyquickstart1.zip