5-Minute Intro to Gradle

Dependencies want to be managed! Gradle makes it easy, even if you’ve been intimidated by other tools before. Let’s get a new project up and running with Apache Commons, JUnit and IntelliJ IDEA.

0. Install Gradle

Head on over to http://gradle.org to download the version for your platform. If you’re a Mac/Homebrew user, it’s this easy:

$ brew install gradle

1. Create Standard Maven Layout

Note The bit of awesomeness between the braces is called shell expansion.

$ mkdir -p my-project/src/{main,test}/java

2. Create Build File

It’s a very simple text file at the root of your project. Any text editor will do.

$ cd my-project
$ vim build.gradle

The file should look like this:

apply plugin: 'java'                                // applies many conventions
apply plugin: 'idea'                                // adds tasks to generate project file (with sources!)

repositories {
    mavenCentral()                                  // find your dependencies on http://search.maven.org

dependencies {
    compile 'org.apache.commons:commons-lang3:3.1' // add project dependencies here
    testCompile 'junit:junit:4.11'                 // test-only dependencies here

3. Generate IntelliJ Project with Dependencies

$ gradle idea

Now all that’s left is to open my-project.ipr. The folders are correctly set up, the sources for your libraries are available, and your dependencies don’t need to be included in your build system.

For web-related fun, check out the war plugin. If you’re an eclipse user, check out the eclipse plugin. Happy Gradling!

Hitting The Ground Running with Android Maven Plugin

This article covers getting up and running with android-maven-plugin. The material is a little dated now that most of the android community has moved on to the official gradle plugin, but the underlying theme of saving time by having a build for your mobile apps still rings true.

Read More

How Do I Migrate My Gradle Dependencies To Be Transitive?

Lessons learned from a migration to gradle that explicitly defined every single dependency, transitive or not, and how we got to transitive dependencies.

Read More

Released: MavenCentral Gradle-Format Search

This greasemonkey script will let you paste gradle-formatted dependencies directly into http://search.maven.org. Hooray!

Read More

Why Am I Getting an OutOfMemoryError with my Ant Task?

Sometimes ant builds run out of memory right in the middle of a task. This article walks through setting up the ANT_OPTS environment variable.

Read More

Build-Breaking Metrics

When choosing how to break the build in your CI-friendly team, make sure to consider all the possible workarounds and how much they may hurt your overall efforts towards quality. After working on several teams, I’ve decided I’m firmly on the side of tracking metrics, but not breaking builds because of them.

Read More

  • 1