IDE Build-Free Web Apps with Gradle

Here’s a good quote from Chapter 5 of Making Java Groovy.

“Some companies still do their builds inside integrated development environments (IDEs). Although this is not in itself a bad thing, it often leads to long-term problems. Sooner or later such companies wind up with a special computer that no one is allowed to touch, even though the original owner left or transferred to another division long ago, because it’s the only system where the build still works.”

That’s pretty funny, but holds a lot of truth. I’ve decided that even for personal projects I’m going to stay in Gradle for building my apps, and that includes the WAR and exploded WAR for everyday development in IntelliJ IDEA.

The Exploded War

Here are the highlights of our file which create our WAR and exploded WAR.

First we apply the WAR Gradle Plugin.

apply plugin: 'war'

We create an explodedWar Gradle task…

task explodedWar(type: Copy) {
into "$buildDir/exploded"
with war

which we’ll execute at the end of the WAR task.

war {
version = version

As part of our IDE Build-Free philosophy we’ll run the Gradle :clean and :war tasks in IntelliJ’s integrated console.

Our output is in our project /build directory, with our exploded WAR in /build/exploded.


In Tomcat we’ll create a quick soft link to our /build/exploded directory.

Now we can hit the site with http://localhost:8080/spricket, though hopefully you have a friendly name for tomcat, something like http://tomcat if you’re really creative like me. You could also create a Tomcat Virtual Host with the Apache Proxy and Proxy_http modules which I blogged about here. Then you could go directly to http://yoursite or in our case, http://spricket.

IntelliJ Tomcat Configuration

If you really, really want to use Tomcat within IntelliJ, you can create an Artifact from the exploded war output as directory content.

Another option would be to select the location as an “external resource” for Tomcat deployment without first creating an Artifact.

Gradle purist like ourselves, however, wouldn’t consider performing IDE-ish procedures like those. Yousa!