8

I'm writing a java library foo which has a dependency on bar:1.1+. But library bar has changed quite a bit over the time, and I'd like to ensure my library is compatible with every version of bar (1.1 ... 1.10).

So I'd like (during CI) to run each of my unit tests with a classpath including bar:1.X, with every version available of bar.

I'm using gradle and junit/spock but I'm open to solutions with variations.

Right I can duplicate by gradle test tasks, but that's pretty cumbersome, and the tests results may be difficult to aggregate. Ideally I'd define right next to my test which versions of bar it should run with, e.g.:

@RunWith("com.acme:bar:1.1..1.10")
public class MyTest { ... }

But I find no tool/runner for that.

Gluck
  • 2,933
  • 16
  • 28
  • 1
    Well, with Maven you could simply define multiple profiles and start the tests with these profiles accordingly (see http://stackoverflow.com/questions/166895/different-dependencies-for-different-build-profiles-in-maven ). I guess gradle has similar possibilities. – Florian Schaetz Aug 11 '15 at 18:39
  • 2
    Just wanted to note that the tests you want to run here are actually integration tests, not unit tests. For unit tests, it would be usual to mock out the dependency on the bar library. – unigeek Aug 11 '15 at 20:04
  • @unigeek not saying you're wrong, but it may depend what library `bar` is, let's say it's guava, no sane man will mock all its uses ^^ – Gluck Aug 11 '15 at 22:44
  • 1
    Perhaps you can somehow generate dependency configurations in Gradle for which each configuration has one version of the dependency. And then run the test task against those configurations. I'm sorry I'm not a Groovy expert to hint you on the code. – Gijs Sep 15 '15 at 13:49
  • Do you use a build tool? Which one? Maven, Gradle? What CI system are you using? Jenkins? GitHub Acrions? – Michael Mar 30 '20 at 13:08

1 Answers1

0

This is related to Maven and not sure how its going fit with CI but may help you get started.

One option may be to use the Maven Archetype <- More Info

Using the mvn archetype:generate, you can generate project with the version you need dynamically

mvn archetype:generate                                  
  -DarchetypeGroupId=<archetype-groupId>                
  -DarchetypeArtifactId=<archetype-artifactId>          
  -DarchetypeVersion=<archetype-version>                
  -DgroupId=<my.groupid>                                
  -DartifactId=<my-artifactId>
  -Dversion=<custom-version>
Garry
  • 4,493
  • 3
  • 28
  • 48
  • I'm not familiar with maven archetypes, but AFAICT this will only help me generate one project per dependency version, which I'd like to avoid and keep a single project. – Gluck Aug 11 '15 at 22:52