# How to exclude an artifact from dependencies?

**URL:** <https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518>\
**Category:** Old Forum Archive\
**Created:** [May 15, 2014, 8:47am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518 "2014-05-15T08:47:00Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gagan\_B\_Mishra](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gagan_b_mishra/32/935_2.png) [@Gagan\_B\_Mishra](https://discuss.gradle.org/u/Gagan_B_Mishra)\
**Post date:** [May 15, 2014, 8:47am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/1 "2014-05-15T08:47:00Z")

</div>

I have added this as my dependency :

```gradle
compile('org.apache.hive:hive-exec:0.12.0'){
  exclude group: 'org.jboss.netty', module: 'netty'
 }

```

This should exclude the netty package from being used in libs as I believe. However, I still find that jar in my build/libs directory.

I checked in ‘gradle dependencies’ and I am sure no other artifact is getting this netty package.

How do I exclude this from getting into libs ?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 15, 2014, 9:35am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/2 "2014-05-15T09:35:00Z")

</div>

The syntax is correct. Note that when using per-dependency excludes, ‘netty’ may still be pulled in by another dependency. Also, ‘build/libs’ typically contains the libraries produced by the build, not their dependencies.

---

<div class="post-metadata">

**Author:** ![Gagan\_B\_Mishra](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gagan_b_mishra/32/935_2.png) [@Gagan\_B\_Mishra](https://discuss.gradle.org/u/Gagan_B_Mishra)\
**Post date:** [May 15, 2014, 9:44am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/3 "2014-05-15T09:44:00Z")

</div>

Ok. There were some other packages pulling this netty. I found that only after doing

```gradle
gradle dependencyInsight --dependency netty

```

But it didn’t show me in ‘gradle dependencies’.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 15, 2014, 10:05am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/4 "2014-05-15T10:05:00Z")

</div>

‘gradle dependencies’ should definitely show it as well (but it will be harder to find). Hard to believe that it doesn’t.

---

<div class="post-metadata">

**Author:** ![Gagan\_B\_Mishra](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gagan_b_mishra/32/935_2.png) [@Gagan\_B\_Mishra](https://discuss.gradle.org/u/Gagan_B_Mishra)\
**Post date:** [May 15, 2014, 10:32am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/5 "2014-05-15T10:32:00Z")

</div>

Strange indeed. But it really isn’t showing in gradle dependencies. I can give you the outputs of both ‘gradle dependencies’ and ‘gradle dependencyInsight --dependency netty’ if you are interested.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 15, 2014, 10:53am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/6 "2014-05-15T10:53:00Z")

</div>

You could post them as a Github Gist or similar.

---

<div class="post-metadata">

**Author:** ![Gagan\_B\_Mishra](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gagan_b_mishra/32/935_2.png) [@Gagan\_B\_Mishra](https://discuss.gradle.org/u/Gagan_B_Mishra)\
**Post date:** [May 15, 2014, 11:07am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/7 "2014-05-15T11:07:00Z")

</div>

Please find them here : [https://gist.github.com/gagan-theKratos/4f93d0e56f8652e36eab](https://gist.github.com/gagan-theKratos/4f93d0e56f8652e36eab) I have added the output from gradle dependencies, gradle dependencyInsight, and the dependency declared in build file. The one I am having trouble is “netty:3.2.2”. Please note that I have to include other netty versions but not this one.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 15, 2014, 11:10am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/8 "2014-05-15T11:10:00Z")

</div>

If you search for “3.2.2”, you’ll immediately find it in the ‘gradle dependencies’ output as well.

---

<div class="post-metadata">

**Author:** ![Gagan\_B\_Mishra](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gagan_b_mishra/32/935_2.png) [@Gagan\_B\_Mishra](https://discuss.gradle.org/u/Gagan_B_Mishra)\
**Post date:** [May 15, 2014, 11:14am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/9 "2014-05-15T11:14:00Z")

</div>

Of course. But it shows under ‘org.apache.hive:hive-exec:0.12.0’, while in dependency insight, it shows that 3.2.2 is coming from other packages as well, e.g, org.apache.kafka:kafka\_2.10:0.8.0 … If i rely on gradle dependency output and exclude it just from ‘hive-exec’, the jar is not really getting excluded.

---

<div class="post-metadata">

**Author:** ![Gagan\_B\_Mishra](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gagan_b_mishra/32/935_2.png) [@Gagan\_B\_Mishra](https://discuss.gradle.org/u/Gagan_B_Mishra)\
**Post date:** [May 15, 2014, 11:15am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/10 "2014-05-15T11:15:00Z")

</div>

My question is, shouldn’t it show under ALL the packages that use this guy ? Like it does in ‘dependency insight’ ? Or my understanding is wrong ?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 15, 2014, 11:23am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/11 "2014-05-15T11:23:00Z")

</div>

It seems that you are misinterpreting the dependencyInsight output, which says that ‘netty:3.2.2.Final’ is (only) a direct dependency of ‘zookeeper:3.4.5’, which in turn is a direct dependency of ‘kafka\_2.10:0.8.0’ and others.

---

<div class="post-metadata">

**Author:** ![Gagan\_B\_Mishra](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gagan_b_mishra/32/935_2.png) [@Gagan\_B\_Mishra](https://discuss.gradle.org/u/Gagan_B_Mishra)\
**Post date:** [May 15, 2014, 11:28am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/12 "2014-05-15T11:28:00Z")

</div>

Yes, I understood that. And the top level package which drags it is “org.apache.spark:spark-streaming-kafka\_2.10:0.9.0-incubating” (As seen in insight). If I exclude netty from this, in my build script, all works fine as expected . But I am still confused on the fact that, shouldn’t ‘gradle dependencies’ also show me that “org.apache.spark:spark-streaming-kafka\_2.10:0.9.0-incubating” depends on “netty:3.2.2” .

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 15, 2014, 11:28am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/13 "2014-05-15T11:28:00Z")

</div>

PS: If you want one particular version of Netty, it would be better to force that version than to exclude all other versions.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [May 15, 2014, 11:40am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/14 "2014-05-15T11:40:00Z")

</div>

> shouldn’t ‘gradle dependencies’ also show me that […]

It does if you expand the ‘(\*)’, which means “not repeating this subtree as it was already shown before”. The purpose of ‘dependencyInsight’ is to make it easier to see how a certain dependency gets dragged in.

---

<div class="post-metadata">

**Author:** ![Gagan\_B\_Mishra](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gagan_b_mishra/32/935_2.png) [@Gagan\_B\_Mishra](https://discuss.gradle.org/u/Gagan_B_Mishra)\
**Post date:** [May 15, 2014, 11:48am UTC](https://discuss.gradle.org/t/how-to-exclude-an-artifact-from-dependencies/7518/15 "2014-05-15T11:48:00Z")

</div>

Ok. I see this now. Thanks for the clarification.
