Sun
Sun

Reputation: 580

How to use multiple versions Jersey (1.8.x and 2.15) in one Java project?

I have two maven projects: projA and projB

projB depends on projA

projB depends on Jersey 2.15

projA depends on hbase-testing-utils

hbase-testing-utils depends Jersey 1.8.x

If projB declares dependency on projA without any exclusions, then projB's tests fail because they use the wrong version (1.8.x) of some class in Jersey project.

If projB declares dependency on projA with exclusions for jersey components, then the above problem goes away. But the new problem is that during test run, projA is not able to find ServletContainer (Jersey 1.8.x) because of the exclusion. projA uses hbase testing utils to spin up an in-memory hbase server which underneath uses Jersey 1.8.x.

I need to use Jersey 2.15 in projB but I also need to exclude Jersey 1.8.x from projA to avoid Null Pointer Exceptions as a result of wrong version classes being used.

How do I solve this problem?

Upvotes: 2

Views: 973

Answers (2)

pawinder gupta
pawinder gupta

Reputation: 1265

Jersey 2 is implementation of JAX-RS 2. Jersey 1.8 is implementation of JAX-RS 1. JAX-RS 2 is not backward compatible and some of the method signatures conflict with each other. You can not include Jersy1.8 and Jersey2 in the same project. It will compile but will fail during runtime.

Upvotes: 1

Anhermon
Anhermon

Reputation: 309

Maybe you can exclude jersey from the dependency on projA, and add it separately but with scope "test".

this should make it available for the test, but not during the other phaces.

Upvotes: 0

Related Questions