Václav is a programming enthusiast who's constantly seeking ways to make development more effective and enjoyable. He's particularly interested in server-side Java technologies, distributed systems, concurrency, agile methodologies, modern programming languages and DSLs. He works for JetBrains as a senior software developer and a technology evangelist. He is also a board member of the JetBrains Academy. On the side, he's leading the GPars project, an opensource concurrency library, and investigates the domains of neural networks, evolutionary programming and data mining. You can check out his blog or follow him on twitter. [dzone] Václav is a DZone Zone Leader and has posted 45 posts at DZone. View Full User Profile

Automate Grails App Builds with TeamCity

  • submit to reddit

The Grails framework has reached maturity with the recent release of its 1.0 version. As Grails is becoming increasingly popular and more and more enterprise applications based on Grails started appearing, I believe that Grails developers deserve the same level of tool support that is available to plain Java developers. This applies not only to IDEs, but also to continuous integration servers. Grails projects' needs for continuous integration don't differ from needs of any other enterprise projects.

TeamCity is a continuous integration server with many unique features, like pre-tested commit, unit and integration testing, integrated test reports, tight IDE (Eclipse, Visual Studio and IntelliJ IDEA) integration, code coverage calculation and reporting, parallel builds, VCS-event-based build triggering and many others. The good news is that most of these features are available to Grails projects as well. In my short series of how-to articles I'll show you how to configure TeamCity to leverage its full power for your Grails applications.

The ultimate goal

First I'll build your appetite with a couple of screenshots from my project build to demonstrate the options you have. We will gradually get to a point when you will be able to get the same screenshots from your own Grails project, I'm sure.


You can quickly navigate to test reports.

And view the reports on-line


The generated war file of your Grails application can be downloaded with a single click


Cobertura code-coverage reports can be generated

And viewed on-line

Canoo webtest report online

How to jump-start your build process.

I assume you are familiar with Grails and TeamCity already.
TeamCity uses a powerfull concept of build agent grid, when the server distributes builds to any available build agent in the network, which is compatible with the build requirements. As Grails applications rely on Groovy and Grails installations, you need to install Groovy and Grails on at least one agent so that the agent can build your applications.
Grails projects themselves need to be configured in TeamCity just like any other projects. The only two steps that deserve our attention in this document are choosing a runner and setting agent requirements.


For a quick start I recommend using the command line runner to invoke grails commands directly as this is the easiest way to build Grails applications. The Ant runner is a little bit more demanding on configuration, but gives you many more options in exchange, so I'll cover it in a dedicated post.
Now back to the command-line runner. You specify "grails.bat" on Windows or "grails" on unixs in the Command executable field. In the Command parameters field you need to specify the grails command to invoke and and in the Artifact paths you set the path to files that your command is supposed to generate and you want to gain access to. This works well for war file generation, but for test reports it is not very convenient to have to download multiple report files. We will resolve this issue with later when configuring the Ant runner.


Configure ant runner to build the app and run tests

Configure ant runner to generate a war file.

Agent requirements

To enable running Grails app builds only on Grails-compatible agents the following environment variables must be required to be set on the agent for all configurations:
Path:contains grails

Set the required agent environment properties


Certainly there are limitations compared to Java projects. For example, the test or webtest reports are not integrated into TeamCity and you have to retrieve them manually as project artifacts. Code coverage is also not supported for the command line runner. In the next article I'll cover the Ant runner, which will help us easily overcome these issues. 

Published at DZone with permission of its author, Václav Pech.


Waseem Bashir replied on Wed, 2010/03/31 - 4:08am

Hi there,

Excellent Article.

My current requirement is:

I have to package my grails app and use teamcity for continuous build.
The only problem is the build agents don't have groovy and grails installed (don't ask why corporate strategic plan to keep the agents light weight)

I want to package my app with Groovy and Grails directories and check in Git. So that there is no dependency on installing groovy and grails on the build agents. And the package has everything to run the app.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.