# Maven style dependencyManagement

**URL:** https://discuss.gradle.org/t/maven-style-dependencymanagement/546
**Category:** Old Forum Archive
**Created:** [November 2, 2011, 6:32pm UTC](https://discuss.gradle.org/t/maven-style-dependencymanagement/546 "2011-11-02T18:32:00Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![juha\_ranta](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@juha\_ranta](https://discuss.gradle.org/u/juha_ranta)
#### Post date: [November 2, 2011, 6:32pm UTC](https://discuss.gradle.org/t/maven-style-dependencymanagement/546/1 "2011-11-02T18:32:00Z")

</div>

So, I’m working in a fairly large organization with lots of projects, some quite small, some rather large. I’ve implemented a uniform build system with Ant+Ivy, later on we switched to Maven. There are many projects and they need to stay similar in constitution, so that the developers can switch projects easily, etc. Many of the developers don’t need to understand the build scripts that much, they mostly just need to change versions of the dependencies. Also, some of our projects are big multi-projects where we need one place to change the dependency version in.

When considering Gradle as a replacement in a situation like this, one thing that to me seems to be missing is something like Maven’s “dependencyManagement”.

Here’s another thread on this subject:

[http://gradle.1045684.n5.nabble.com/Multiproject-dependencies-using-Maven-style-dependencyManagement-td3305232.html](http://gradle.1045684.n5.nabble.com/Multiproject-dependencies-using-Maven-style-dependencyManagement-td3305232.html)

The solutions given there don’t seem satisfactory to me. For one, I want to use the map style when declaring the dependencies. I don’t want to give the developers the task of figuring new names for dependencies. Etc.

So, I’d like to see some way to set at least the versions of the dependencies in the parent pom without creating new variables, etc.

Perhaps something like this in the parent project:

```gradle
subprojects {
     dependencyManagement {
                   compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
     }
}

```

Then in a subproject:

```gradle
subprojects {
     dependencies {
                   compile group: 'org.hibernate', name: 'hibernate-core'
     }
}

```

This would get the version and other attributes from the dependencyManagement.

To think of it, in our case it’s mostly the problem of configuring the version numbers in one place. I don’t like the idea of creating new variables for this. Perhaps someone can come up with a more elegant solution.

---

<div class="post-metadata">

### Author: ![Andrew\_Oberstar](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@Andrew\_Oberstar](https://discuss.gradle.org/u/Andrew_Oberstar)
#### Post date: [November 2, 2011, 9:14pm UTC](https://discuss.gradle.org/t/maven-style-dependencymanagement/546/2 "2011-11-02T21:14:00Z")

</div>

How about a flavor of what Peter suggested in that thread.

In the root project:

```gradle
subprojects {
  libaries = [
    'hibernate-core':[group:'org.hibernate', name:'hibernate-core', version:'3.6.7.Final']
  ]
}

```

In the subprojects:

```gradle
dependencies {
  compile libraries.'hibernate-core'
}

```

Haven’t tested that, but something like that should work.

---

<div class="post-metadata">

### Author: ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)
#### Post date: [November 3, 2011, 5:05am UTC](https://discuss.gradle.org/t/maven-style-dependencymanagement/546/3 "2011-11-03T05:05:00Z")

</div>

It’s good enough to declare ‘libraries’ in the root project (it’s visible from subprojects). Personally I also prefer the short dependency notation ‘org.hibernate:hibernate-core:3.6.7.Final’. For cases where the shared dependency needs advanced configuration (say an exclude) there is ‘dependencies.create()’.

---

<div class="post-metadata">

### Author: ![Ray](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@Ray](https://discuss.gradle.org/u/Ray)
#### Post date: [November 29, 2011, 4:22pm UTC](https://discuss.gradle.org/t/maven-style-dependencymanagement/546/4 "2011-11-29T16:22:00Z")

</div>

Hi: I tried the solutions, but still run into issues.

So the root build.gradle looks like this:

subprojects {

apply plugin: ‘java’

apply plugin: ‘maven’

apply plugin: ‘eclipse’

cxf\_version = ‘2.3.5’

commons\_version = ‘1.4.7’

version = ‘0-SNAPSHOT’

repositories {

mavenCentral artifactUrls: [“[http://lnyce25218.bankofamerica.com:8081/nexus/content/groups/master](http://lnyce25218.bankofamerica.com:8081/nexus/content/groups/master)”]

}

libraries = [

‘cxf’:[‘org.apache.cxf:cxf-rt-core:2.3.5’]

]

jar {

manifest {

attributes ‘Implementation-Title’: ‘Gradle Quickstart’, ‘Implementation-Version’: version

}

} }

The child project: buildscript {

repositories {

mavenCentral artifactUrls: [“[http://lkcma00029.bankofamerica.com:8081/nexus/content/groups/master](http://lkcma00029.bankofamerica.com:8081/nexus/content/groups/master)”]

}

dependencies {

compile libraries.‘cxf’

} }

I kept on getting this error.

- Where: Build file ‘C:\projects\open\main\wrapper\cxf\build.gradle’ line: 7

- What went wrong: A problem occurred evaluating project ‘:wrapper:cxf’. Cause: No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argum ent types: (java.util.ArrayList) values: [[org.apache.cxf:cxf-rt-core:2.3.5]] Possible solutions: module(java.lang.Object)

- Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

The debug message shows following: 10:21:12.343 [ERROR] [org.gradle.BuildExceptionReporter]

at org.gradle.launcher.GradleMain.main(GradleMain.java:24) 10:21:12.343 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: groovy.lang.MissingMethodException: No signature of method: org.gradle.a pi.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argument types: (java.util.ArrayList) values: [[org.apache.cxf:cxf-rt-core:2.3.5]] Possible solutions: module(java.lang.Object) 10:21:12.359 [ERROR] [org.gradle.BuildExceptionReporter]

at org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandl er.methodMissing(DefaultDependencyHandler.groovy:94)

---

<div class="post-metadata">

### Author: ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)
#### Post date: [November 29, 2011, 4:28pm UTC](https://discuss.gradle.org/t/maven-style-dependencymanagement/546/5 "2011-11-29T16:28:00Z")

</div>

You need to apply the ‘java’ plugin to get a ‘compile’ configuration.

---

<div class="post-metadata">

### Author: ![Ray](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@Ray](https://discuss.gradle.org/u/Ray)
#### Post date: [November 29, 2011, 4:37pm UTC](https://discuss.gradle.org/t/maven-style-dependencymanagement/546/6 "2011-11-29T16:37:00Z")

</div>

Thanks. I thought when declared apply plugin: ‘java’ at root level, all child projects inherit the plugin automatically. Anyway, I just added plugin to the child project which now looks like this:

buildscript {

apply plugin: ‘java’

repositories {

mavenCentral artifactUrls: [“[http://lkcma00029.bankofamerica.com:8081/nexus/content/groups/master](http://lkcma00029.bankofamerica.com:8081/nexus/content/groups/master)”]

}

dependencies {

compile libraries.‘cxf’

} }

And I am still getting this error:

buildscript {

apply plugin: ‘java’

repositories {

mavenCentral artifactUrls: [“[http://lkcma00029.bankofamerica.com:8081/nexus/content/groups/master](http://lkcma00029.bankofamerica.com:8081/nexus/content/groups/master)”]

}

dependencies {

compile libraries.‘cxf’

} }

---

<div class="post-metadata">

### Author: ![Ray](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@Ray](https://discuss.gradle.org/u/Ray)
#### Post date: [November 29, 2011, 4:42pm UTC](https://discuss.gradle.org/t/maven-style-dependencymanagement/546/7 "2011-11-29T16:42:00Z")

</div>

sorry, the build error is listed as follows:

C:\projects\open\main\>gradle build

FAILURE: Build failed with an exception.

- Where: Build file ‘C:\projects\open\main\wrapper\cxf\build.gradle’ line: 9

- What went wrong: A problem occurred evaluating project ‘:wrapper:cxf’. Cause: No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argum ent types: (java.util.ArrayList) values: [[org.apache.cxf:cxf-rt-core:2.3.5]] Possible solutions: module(java.lang.Object)

- Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

---

<div class="post-metadata">

### Author: ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)
#### Post date: [November 29, 2011, 4:54pm UTC](https://discuss.gradle.org/t/maven-style-dependencymanagement/546/8 "2011-11-29T16:54:00Z")

</div>

I can’t tell exactly what you are trying to do, but probably the whole ‘buildscript { … }’ needs to go away, and just its contents remain. Also the repository declaration should be changed to:

```gradle
repositories {
  maven {
    url "http://..."
  }
}

```

---

<div class="post-metadata">

### Author: ![Ray](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@Ray](https://discuss.gradle.org/u/Ray)
#### Post date: [November 29, 2011, 8:41pm UTC](https://discuss.gradle.org/t/maven-style-dependencymanagement/546/9 "2011-11-29T20:41:00Z")

</div>

great. Thanks a lot Peter.

---

<div class="post-metadata">

### Author: ![James\_Carnegie](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/james_carnegie/32/1019_2.png) [@James\_Carnegie](https://discuss.gradle.org/u/James_Carnegie)
#### Post date: [July 10, 2012, 4:50pm UTC](https://discuss.gradle.org/t/maven-style-dependencymanagement/546/10 "2012-07-10T16:50:00Z")

</div>

Another use of the dependencyManagement feature in Maven is to point to a bill of materials POM, say for CXF, and use the the version numbers of CXFs dependencies, without having to explicitly use them in the “dependencies” section. That way, the requirement is only to rev the version of CXF to retrieve all the versions of its dependencies.

Is it possible to do something similar in Gradle?

---

<div class="post-metadata">

### Author: ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)
#### Post date: [July 10, 2012, 5:06pm UTC](https://discuss.gradle.org/t/maven-style-dependencymanagement/546/11 "2012-07-10T17:06:00Z")

</div>

A rough equivalent would be a plugin that provides aliases for certain dependencies. Bill of material POMs aren’t currently supported out-of-the-box.
