Issues on including multiple versions of a dependency for writing Unit Tests in Gradle

buildship

(Sumit Maheshwari) #1

Currently we have a gradle project which is responsible for running testng unit tests.
These are unit tests which verifies support provided for different versions of a framework.

Let me elaborate the problem with an example:
Let’s say I start supporting Akka version 2.3.X and as a good practice write a Unit Test which would need to include few akka jar’s as test-compile dependency.
Now after some time we plan to support Akka version 2.3.Y. And obviously we would need to write a Unit Test which would need to include few akka jar’s again but of different version.
And bang here we have the problem. Currently our Unit test runs on a single JVM and at one time we can have only one version of “artifact” be loaded. So we are left with choice of choosing one version of jar and may be try to mock the other one. But again for frameworks like Akka mocking may turn into nightmare.

One crude way is we could create a bunch of new projects. But that would be too verbose.
Is there a way in gradle where we would define multiple test tasks, each bound with a specific configuration?


(uklance) #2

You could add another Test task (eg test2) to the project which has a different classpath (eg a testRuntime2 configuration)

In fact, you might even find you can use my java-flavours-plugin for this.

Eg:

apply plugin: 'com.lazan.javaflavours' 
javaFlavours { 
   flavour 'akka1' 
   flavour 'akka2' 
} 
dependencies { 
   compile 'common:common:1.0'
   akka1Compile 'akka:akka:1.0'
   akka2Compile 'akka:akka:2.0'
}

Custom sources could then be put in src/akka1/java and src/akka1Test/java etc