# Defining multiple jar dependencies

**URL:** <https://discuss.gradle.org/t/defining-multiple-jar-dependencies/10857>\
**Category:** Help/Discuss\
**Created:** [July 29, 2015, 12:00pm UTC](https://discuss.gradle.org/t/defining-multiple-jar-dependencies/10857 "2015-07-29T12:00:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Smith](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Mike\_Smith](https://discuss.gradle.org/u/Mike_Smith)\
**Post date:** [July 29, 2015, 12:00pm UTC](https://discuss.gradle.org/t/defining-multiple-jar-dependencies/10857/1 "2015-07-29T12:00:25Z")

</div>

We have a multi-module build setup (about 60 projects), but our library dependency management is very unsophisticated. I’d like to simplify and make it more flexible wrt future library upgrades.

For example, we have multiple projects defined with the following style dependencies (in each project build.gradle):

```
compile ' lib:spring-3.1.1/org.springframework.aop-3.1.1.RELEASE'

        compile
' lib:spring-3.1.1/org.springframework.asm-3.1.1.RELEASE'

        compile
' lib:spring-3.1.1/org.springframework.aspects-3.1.1.RELEASE'

        compile
' lib:spring-3.1.1/org.springframework.beans-3.1.1.RELEASE'

        compile
' lib:spring-3.1.1/org.springframework.context-3.1.1.RELEASE'

```

Its a longer list in reality! We are using flat file repositories.

I would like to change this to a single dependency declaration and separately define this as a collection of jars in the top level build.gradle file or somewhere similar, a bit like a group of external dependencies?

I have seen brief mentions of dependencies.gradle where this might be defined (?), but have not found any examples of usage.

Any pointers much appreciated.

Regards,  
Mike

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [July 29, 2015, 1:33pm UTC](https://discuss.gradle.org/t/defining-multiple-jar-dependencies/10857/2 "2015-07-29T13:33:21Z")

</div>

For an example of a dependencies.gradle that has several groups of external dependencies, look at the Gradle project itself. The collections of dependencies are created under `libraries.`_name_ and then referenced that way in the dependencies blocks of the various modules. The root project uses `apply from: 'dependencies.gradle'` to pull in this dependency information.

> <https://github.com/gradle/gradle/blob/master/gradle/dependencies.gradle>

---

<div class="post-metadata">

**Author:** ![Mike\_Smith](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Mike\_Smith](https://discuss.gradle.org/u/Mike_Smith)\
**Post date:** [July 29, 2015, 2:34pm UTC](https://discuss.gradle.org/t/defining-multiple-jar-dependencies/10857/3 "2015-07-29T14:34:07Z")

</div>

Thanks James, working a treat for me

---

<div class="post-metadata">

**Author:** ![kkrugler](https://avatars.discourse-cdn.com/v4/letter/k/96bed5/32.png) [@kkrugler](https://discuss.gradle.org/u/kkrugler)\
**Post date:** [July 11, 2017, 5:22pm UTC](https://discuss.gradle.org/t/defining-multiple-jar-dependencies/10857/4 "2017-07-11T17:22:15Z")

</div>

Is there a simpler version that shows how to just change one jar dependency when building for test vs. production? Specifically there’s a compile-scope jar that must be included for a war build, but must not be included for unit tests.

Thanks!

– Ken

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [July 16, 2017, 12:47am UTC](https://discuss.gradle.org/t/defining-multiple-jar-dependencies/10857/5 "2017-07-16T00:47:49Z")

</div>

The original question is about declaring all libraries for your project in a single location and grouping the ones that would be used together so that individual projects can use aliases rather than multiple full dependency declarations. This is a completely different concern from what you’re asking about.

You instead want to exclude a particular dependency from the relevant test related configuration: `testCompile`, `testRuntime`, or `testImplementation` (if you’re using a new enough version to start using the new configurations).

```groovy
dependencies {
    compile 'com.example:no-test:1.0'
}

configurations {
    testCompile.exclude group: 'com.example', module: 'no-test'
}

```
