wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes Gradle Dependency Version Control Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Gradle Dependency Version Control" Watch "Gradle Dependency Version Control" New topic

Gradle Dependency Version Control

Mike Gage

Joined: Jan 22, 2002
Posts: 9
I have become accustomed to working with Maven. Our company is now widely adopting Gradle in place of Maven. One of the features I enjoy in Maven is dependency management in a parent project to control dependency versions in subprojects. I am sure that there is an equivalent mechanism in Gradle. What is the preferred way to do that?

Thank you,

Mike Gage
Hubert Klein Ikkink

Joined: Jan 10, 2013
Posts: 13

Hi Mike,

Gradle allows to simply define variables and assign dependency artefact names to them. You can then use the variable in subprojects or where you want to define dependencies.
For example for a multiproject build file we could have the following build file:

apply plugin: 'java'

def springVersion = '3.2.0.RELEASE'
def springModule = 'org.springframework'

def springLibs = [core: "$springModule:spring-core:$springVersion", test: "$springModule:spring-test:$springVersion"]
def junitLib = "junit:junit:4.10+"

allprojects {

dependencies {
compile springLibs.core
testCompile springLibs.test

project(':special') {
dependencies {
testCompile junitLib

// To remove spring-test dependency
configurations {
testCompile.exclude springLib.test
Mike Gage

Joined: Jan 22, 2002
Posts: 9
Very cool!

Thank you.
Consider Paul's rocket mass heater.
subject: Gradle Dependency Version Control
Similar Threads
Using multiple IDEs
* Welcome Hubert Klein Ikkink
stop downloading libraries everytime
Spring classes not resolved even with libs added
Build tools comparison