title: How to exclude a package from a transitive dependency of external jar included in build.gradle?
body: <p>I have included the following dependency in my build.gradle:</p>
  
  <pre><code>testCompile group: 'com.xebialabs.restito', name: 'restito', version:'0.5.1'
  </code></pre>
  
  <p>But with this jar other dependencies like <em>jersey-core-1.18.3.jar</em> also get included.</p>
  
  <p>Now I want this jersey jar but this also has a package <em>javax.ws.rs.core</em> which contains classes that conflict with my latest version of javax.ws.rs.core included explicitly in build.gradle.</p>
  
  <p>Is there any way that I can exclude only a specific package from a transitive dependency and not the whole dependency. I am a newbie to gradle so please correct  me if any incorrect term was used.</p>
  
  <p>When I run the following command:</p>
  
  <pre><code>gradlew dependencies --configuration testCompile
  </code></pre>
  
  <p>it gives me following dependency tree. Only the relevant part is shown here</p>
  
  <pre><code>testCompile - Compile classpath for source set 'test'.
  
  +--- org.apache.cxf:cxf-rt-frontend-jaxrs:3.0.3
  |    +--- org.apache.cxf:cxf-core:3.0.3 (*)
  |    +--- javax.ws.rs:javax.ws.rs-api:2.0.1
  |    +--- javax.annotation:javax.annotation-api:1.2
  |    \--- org.apache.cxf:cxf-rt-transports-http:3.0.3 (*)
  +--- org.apache.cxf:cxf-rt-rs-service-description:3.0.0-milestone1
  |    \--- org.apache.cxf:cxf-rt-frontend-jaxrs:3.0.0-milestone1 -&gt; 3.0.3 (*)
  +--- org.codehaus.jackson:jackson-jaxrs:1.9.13
  |    +--- org.codehaus.jackson:jackson-core-asl:1.9.13
  |    \--- org.codehaus.jackson:jackson-mapper-asl:1.9.13
  |         \--- org.codehaus.jackson:jackson-core-asl:1.9.13
  +--- org.codehaus.jackson:jackson-mapper-asl:1.9.12 -&gt; 1.9.13 (*)
  +--- com.fasterxml.jackson.core:jackson-databind:2.4.1.2
  |    +--- com.fasterxml.jackson.core:jackson-annotations:2.4.0
  |    \--- com.fasterxml.jackson.core:jackson-core:2.4.1.1
  \--- com.xebialabs.restito:restito:0.5.1
       +--- org.slf4j:slf4j-api:1.7.5 -&gt; 1.7.7
       +--- org.mockito:mockito-core:1.10.17
       |    +--- org.hamcrest:hamcrest-core:1.1 -&gt; 1.3
       |    \--- org.objenesis:objenesis:2.1
       +--- org.apache.mina:mina-core:2.0.4
       |    \--- org.slf4j:slf4j-api:1.6.1 -&gt; 1.7.7
       +--- org.glassfish.grizzly:grizzly-http-server:2.3.17
       |    \--- org.glassfish.grizzly:grizzly-http:2.3.17
       |         \--- org.glassfish.grizzly:grizzly-framework:2.3.17
       +--- junit:junit:4.12
       |    \--- org.hamcrest:hamcrest-core:1.3
       \--- com.sun.jersey:jersey-grizzly2:1.18.3
            +--- org.glassfish.grizzly:grizzly-http:2.2.16 -&gt; 2.3.17 (*)
            +--- org.glassfish.grizzly:grizzly-http-server:2.2.16 -&gt; 2.3.17 (*)
            \--- com.sun.jersey:jersey-server:1.18.3
                 \--- com.sun.jersey:jersey-core:1.18.3
  
  (*) - dependencies omitted (listed previously)
  </code></pre>
  
  <p>Now the class <em><code>Response</code></em> in <em><code>javax.ws.rs:javax.ws.rs-api:2.0.1</code></em> is under the package <em><code>javax.ws.rs.core</code></em>. Similarly there is another <em><code>Response</code></em> class present in <em><code>com.sun.jersey:jersey-core:1.18.3</code></em> in package <em><code>javax.ws.rs.core</code></em>. But the later one contains earlier version which does not has <em><code>readEntity()</code></em> method introduced in rs-api 2.0. The dependency for <em><code>Response</code></em> in my project gets resolved to the earlier version always.</p>