Gradle Dependency Management Tips

Gradle is much better to manage dependencies than Maven. Not only it allows you to set http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html, but it also supports full manual control.

First, if you do not want transitive dependencies at all (you will be forced to explicitly list all libraries in the build file), you can disable them easily:

configurations {all*. transitive = false}

If you are not that radical and want to blacklist some specific library, you can do it:

configurations {all*.exclude group: 'mygroup', module: 'D', version: '1'}

I just recently started using Gradle in a new fresh project and it is awesome! I can't express how much I love it. Check this out:

// Modifies JAR task to create a fat jar (with all the dependencies included in one JAR)
jar {
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

And how much I love being able to check build environment configuration and throw custom errors:

throw new InvalidUserDataException("Unsupported packaging: $packaging. Use onejar|fatjar")

One could say that all of that is available with And and Ivy. And I am not going to argue with such a statement. But Gradle still gently pushing you towards standard project layout, commands and tools. Ant does not. As a result, every single ant project I've seen was different. You would never know what "ant deploy" is going to do. There was one project, where "ant build" was destroying some environment (the last it has been used to deploy to). Can you imagine it?

In any case, Gradle is awesome.