# Build multiple artifacts against a specific dependency's version range

**URL:** <https://discuss.gradle.org/t/build-multiple-artifacts-against-a-specific-dependencys-version-range/24521>\
**Category:** Help/Discuss\
**Tags:** not-a-bug\
**Created:** [October 25, 2017, 3:54pm UTC](https://discuss.gradle.org/t/build-multiple-artifacts-against-a-specific-dependencys-version-range/24521 "2017-10-25T15:54:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ursus](https://avatars.discourse-cdn.com/v4/letter/u/e99b99/32.png) [@ursus](https://discuss.gradle.org/u/ursus)\
**Post date:** [October 25, 2017, 3:54pm UTC](https://discuss.gradle.org/t/build-multiple-artifacts-against-a-specific-dependencys-version-range/24521/1 "2017-10-25T15:54:49Z")

</div>

I am planing to move to Gradle and need to know before if it is possible to build multiple artifacts from a project against a version range of a specific dependency. I’m totally new to Gradle and I googled about this but couldn’t find anything that would help me out here.

Our use case is the following (simplified): We have a core application with a plug-in capability. The plug-in is compatible against multiple core versions but needs to be built against every single one. Up to now, we’ve managed this matrix building with an external script.

An example for what I’d like to achieve:

- The artifact repository stores artifacts for ‘company:core’ for the versions 1.0, 1.5, 2.0, 2.0.1, 3.0, 4.0
- In Gradle:

```gradle
jar {
  baseName = 'myplugin'
  version = '1.0.0'
}

dependencies {
  compile 'company:core:[2.0,3.0]'
  compile 'some:other:1.2.3
}

```

- now, I’d like to compile, run tests, publish artifacts, etc. against the whole version range of ‘company:core’: 2.0, 2.0.1, 3.0. Ideally, the artifacts published will have set the classifier to the version used. Expected artifacts:
  - myplugin-1.0.0-2.0.jar
  - myplugin-1.0.0-2.0.1.jar
  - myplugin-1.0.0-3.0.jar

Is this in any way possible? If yes, how? 😉

Thanks a lot in advance!

---

<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:** [October 26, 2017, 4:24am UTC](https://discuss.gradle.org/t/build-multiple-artifacts-against-a-specific-dependencys-version-range/24521/2 "2017-10-26T04:24:31Z")

</div>

Basically you need a configuration for each core version you want to compile / test against and separate compilation, test, publish task for each one.

However, you don’t need to do this manually. @Lance has a [flavours plugin](https://github.com/uklance/gradle-java-flavours) that should configure most of this for you. You should just need to declare a flavour for each core version and add the correct dependency to the flavour’s dependencies.

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [October 26, 2017, 9:06am UTC](https://discuss.gradle.org/t/build-multiple-artifacts-against-a-specific-dependencys-version-range/24521/3 "2017-10-26T09:06:49Z")

</div>

Yep, the java flavours plugin could do this, something like:

```gradle
plugins {
	id 'com.lazan.javaflavours' version '1.2'
}
ext {
	versionRange = ['1.0', '1.1', '1.2', ... , '1.n']
}
javaFlavours {
	versionRange.each {
		flavour "flavour${it}"
	}
}
versionRange.each {
	dependencies.add("flavour${it}Compile", "com.mygroup:myartifact:$it")
}

```

You could then put flavour specific sources in

- src/flavour${version}/java
- src/flavour${version}/resources
- src/flavour${version}Test/java
- src/flavour${version}Test/resources
