How to exclude an artifact from dependencies?

I have added this as my dependency :

  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 ?

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.

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

gradle dependencyInsight --dependency netty

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

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

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.

You could post them as a Github Gist or similar.

Please find them here : 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.

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

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.

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 ?

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.

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” .

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

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.

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