• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Gradle Dependency Version Control

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 13
IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very cool!

Thank you.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic