Build multiple artifacts against a specific dependency's version range


(Urs Spycher) #1

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:
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? :wink:

Thanks a lot in advance!

(James Justinic) #2

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 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.

(uklance) #3

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

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