one of those blogs

Gradle on Gradle

After a truly awesome presentation about Gradle that Hans Dockter gave at Philly’s Groovy and Grails user group last week, I got really excited about the project. The truth is, if you ever had to do any kind of build work in JVM world, you would feel strict limitations and inflexibility of Maven, hardcore maintenance challenges of ANT ( or ANT + IVY ) with your bones. Well, let your bones relax, here comes Gradle… : )

So where do you start? You can of course go hit the books, or watch some videos, but the true way to learn something is to experience it, at least that is my philosophy.

So here we go, let’s do it, let’s dive in to Gradle “by hand”. I was playing with many examples provided in documentation, but it still felt I am missing a big picture, so I decided to try Gradle out on a real, full blown, mature project. I thought for about 3.14159265 seconds, and decided: “Let me throw Gradle on Gradle itself”. That’s right! Let me get Gradle sources and build them with Gradle.

“So what?” you think, how is it different from “mvn clean install”, or “ant build”? Well, when Maven ‘just works’ (which is 50% of the time on more than 5 people project), this particular step would not be too different. But now I want to look at some pictures to see the project I just built. And for pictures I usually go to IntelliJ : )

Of course you can start IntelliJ, import this project as a “Java project from existing sources”, try to figure out how to set the classpath for a dozen of subprojects, how to create them as modules with good names, add Groovy, Scala, Web Project Facets, etc.. but why to go through such troublesome exercise?

In Grails world, if anybody asks: “Can Grails do that?”, the most definite answer would be: “Of course, there is a plugin for that!” Turns out that Gradle is not much different: you want to create an IntelliJ project? => There is a plugin for that!

But I am here for the first time, so I have no clue what exactly I should be calling to create that IntelliJ project. Well.. why not ask Gradle.

Very cool! So I can “Generate IDEA project files (IML, IPR)” and “Clean IDEA project files (IML, IPR)”. ( Notice how “:idea” task explicitly depends on “:ideaModule, :ideaProject, :ideaWorkspace” ). These tasks are available through Gradle IDEA Plugin, which is one of many plugins that come with Gradle. So let’s create that project:

$ gradle idea

$ gradle idea

4. Gradle in IDE

Once this is done ( takes about 64 seconds ), import it as an IDEA project, and…:

Classpath, modules, workspace, etc.. everything was pre-created by Gradle. So what can you do with the project at this point, besides starting committing your ideas, of course : ) ? Well, let’s ask Gradle, but this time using IntelliJ itself:

Want to take a closer look at what Gradle can do with individual module?

Seems like there are many things that can be done outside of Gradle box, doesn’t it?

If it doesn’t yet, how about posting formal releases to Twitter, Snarl or maybe have it sent as Ubuntu notification? Well, as I mentioned earlier: “there is a plugin for it”:

And just to give you a little taste of a Gradle build script, here is a Gradle DSL to build this plugin:

This was just a little intro, the real Gradle power is very well documented, and is just plain obvious after 5 minutes actually trying Gradle.