0

Is it possible to add older version of the same artifact as dependency? Here is an example:

<groupId>edu.illinois.cs.cogcomp</groupId> <artifactId>illinois-pos</artifactId> <version>2.0.3</version> <dependencies> <dependency> <groupId>edu.illinois.cs.cogcomp</groupId> <artifactId>illinois-pos</artifactId> <version>2.0.2</version> <classifier>model</classifier> </dependency> </dependencies> 

If not, is there any way to make it work?

8
  • Can you explain what you like to achieve cause using the same artifact as a dependenciy does not sounds right to me? Commented Dec 13, 2015 at 8:27
  • We are developing machine learning systems which have big model files (which are using for prediction), and we keep the model files in jar files other than the main jar file. For example here: cogcomp.cs.illinois.edu/m2repo/edu/illinois/cs/cogcomp/… there is a jar file for illinois-pos-2.0.2.jar and one for the model files illinois-pos-2.0.2-model.jar. The reason for keeping them separate is that, not any version has a model file. So one can use older models on a more updated code. Commented Dec 13, 2015 at 9:43
  • ... inside our code we have unit tests which need the model artifacts. So I will make the models available to the code by adding them as dependency. Commented Dec 13, 2015 at 9:44
  • Do you think there is a better way to do it, @khmarbaise? Commented Dec 13, 2015 at 9:44
  • Do you need to have them as part of the same build or can they be part of two separated builds? (you build using the oldest, then you build using the latest, etc.) Commented Dec 13, 2015 at 9:45

2 Answers 2

1

Based on your comments (and further clarification and needs), I would suggest to have a Maven multi-module project structured as following:

  • A module providing the code using the latest dependency, which would not provide any test
  • A module providing only test cases and using the old dependency and as such running the tests on the concerned code by using another dependency. To make it work, the test module must have a dependency on the code module and explicitly re-declare the dependency version you effectively want for the tests.

As such, you would have a an aggregator pom (empty project, no sources, no tests) having packaging pom and defining two modules (i.e., code-module, test-module). You would keep on working on the code-module and then provide your test cases on the test-module, where you can also override and re-define any required dependency.

As such, as part of the same build (on the aggregator project) you could build the two modules as you need.

Alternatively, keeping a single layer module, you could define a profile which would re-define the required dependency (with a different version) and run your test cases. That would also mean that:

  • As part of the default build, you will need to skip tests, configuring the Maven Surefire Plugin to skip tests via a property (i.e. <skip>${skip.tests}</skip>) which would have as default value true
  • You would then need to configure your profile to change the value of the skip.tests property to false and re-define the dependency

With the second approach, you would then need to execute your build twice: first build would run normally but skipping tests (mvn clean install), second build you would activate the profile and starting from the test phase (mvn test -Pprofile-name).

The first approach (multi-module project) is definitely more recommended.

Sign up to request clarification or add additional context in comments.

Comments

0

No, it's not, because maven will just select the later version. That's because at runtime, java can't use both versions - if you had both in the classpath, the first one loaded would "win" and the other wouldn't be used.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.