nikkatsa
nikkatsa

Reputation: 1811

Maven Dependency Selection

I am facing a problem with a web-application that i have.

The web-app uses jersey library and specificaly version 1.8.

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.8</version>
    </dependency>

The problem is that an upstream dependency depends on another Jersey version 2.3 which looks like this:

    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>2.3</version>
    </dependency>

This causes me problems as initially Jersey 1.8 is loaded, but then when methods are invoked it seems that are called in Jersey-server 2.3

I would like to know is there anything i can do to exclude the jersey-server that i don't want?

Upvotes: 1

Views: 531

Answers (2)

NickJ
NickJ

Reputation: 9559

To exclude a transitive dependency:

<project>
...
<dependencies>

 <dependency>
  <groupId>groupid.of.what.needs.jersey</groupId>
  <artifactId>artifactId.of.what.needs.jersey</artifactId>
  <version>1.0</version>
  <exclusions>
    <exclusion>  <!-- declare the exclusion here -->
      <groupId>org.glassfish.jersey.core</groupId>
      <artifactId>jersey-server</artifactId>
      <version>2.3</version>
    </exclusion>
  </exclusions>

</dependency>

But, there's a danger that the other dependency might not be compatible with Jersey 1.8. It would be best to use the same version yourself, if possible.

Upvotes: 4

ben75
ben75

Reputation: 28706

You can exclude dependencies with this kind of declaration in your dependencies section

<dependency>
  <groupId>your.upstream.dependency.groupid</groupId>
  <artifactId>your.upstream.dependency.artifactid</artifactId>
  <version>[upstream.dep.version]</version>
  <exclusions>
    <exclusion>  <!-- declare the exclusion here -->
      <groupId>org.glassfish.jersey.core</groupId>
      <artifactId>jersey-server</artifactId>
    </exclusion>
  </exclusions> 
</dependency>

reference

Be careful that it may have a very bad impact, especially because you are excluding something that seems newer (i.e version 2.3, but with a different groupid)

Upvotes: 2

Related Questions