Reputation: 6039
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?
Upvotes: 0
Views: 1252
Reputation: 27862
Based on your comments (and further clarification and needs), I would suggest to have a Maven multi-module project structured as following:
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:
<skip>${skip.tests}</skip>
) which would have as default value true
skip.tests
property to false
and re-define the dependencyWith 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.
Upvotes: 1
Reputation: 30088
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.
Upvotes: 0