1

In maven, you can declare depenencies versions in dependency management section. Say I have such pom for managing default versions of some libraries for all of my projects (so I don't have to repeat them all over again and so I can ensure some consistency across all of my projects).

Then I have multiple projects(project A and project B) which have this pom set as parent pom. If in project A I want to use spring.jar, and I have spring.jar defined in dependency-management of A's parent pom, I don't have to define spring version in A's pom again, I just define that it depends on spring. So far it's ok, is pretty simple how to do it in gradle too (http://stackoverflow.com/questions/9547170)

What I'm wondering about is this situation:
Imagine that spring 3.0 depends on hibernate 3.0. In A's parent pom I have defined hibernate dependency in dependency-management section with version 3.1, but spring is not defined there. Spring is defined in A's pom (with version 3.0). Dependency resolution in maven for project A would result in fetching spring 3.0 and hibernate 3.1 - because despite fact that spring 3.0 depends on hibernate 3.0, dependency-management of A's parent pom overrides hibernate version, so 3.1 would be used instead.

Is there way of defining something similar in gradle? Note that I didn't have to specify hibernate in A's pom specificly and also it is not specified as dependency in A's parent pom - it is only in dependency-management section of A's parent pom.

mawek
  • 679
  • 10
  • 19
  • Not sure if it will work, but did you already take a look at the [resolutionStrategy](http://gradle.org/docs/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html) class? – Steven Feb 05 '13 at 14:24
  • Maybe this other SO answer will help? http://stackoverflow.com/questions/9547170/in-gradle-how-do-i-declare-common-dependencies-in-a-single-place – Ben Jul 23 '13 at 21:40

1 Answers1

2

The io.spring.dependency-management plugin allows you to use a Maven bom to control your build's dependencies:

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath "io.spring.gradle:dependency-management-plugin:0.5.3.RELEASE"
  }
}

apply plugin: "io.spring.dependency-management"

Next, you can use it to import a Maven bom:

dependencyManagement {
  imports {
    mavenBom 'io.spring.platform:platform-bom:1.1.4.RELEASE'
  }
}

Now, you can import dependencies without specifying a version number:

dependencies {
  compile 'org.springframework:spring-orm'
  compile 'org.hibernate:hibernate-core'
}
matsev
  • 32,104
  • 16
  • 121
  • 156