This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Gradle Dependency Version Control

 
Mike Gage
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Greenhorn
Posts: 13
IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 {
repositories.mavenCentral()

dependencies {
compile springLibs.core
testCompile springLibs.test
}
}

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

// To remove spring-test dependency
configurations {
testCompile.exclude springLib.test
}
}
 
Mike Gage
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very cool!

Thank you.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic