Dependencies Exclude

(ohad.raz) #1

Hi all,

I am not sure if I’m having a problem, or simply misunderstanding, as I am new to gradle.

What I have is the following scenario:

  1. I have a gradle project, call it GP1, which produces an artifact, call it A1. 2. I have a second gradle project, GP2, which produces artifact A2, and has a dependency of A1 artifact. 3. I have a third gradle project, GP3, which produces artifact A3, and has a dependency of artifact A2, excluding A1. 4. I have the fourth and final gradle project, GP4, which produces artifact A4, and has a dependency of A3.

code snippets:

  • GP2 (which produces A2):

dependencies {

someDep1 (‘someGroup:A1:someVersion’)


  • GP3 (which produces A3):

dependencies {

someDep2 (‘someGroup:A2:someVersion’) {

exclude module: ‘A1’



  • GP4:

dependencies {

someDep3 (‘someGroup:A3:someVersion’)


Now, on GP3, executing:

gradle dependencies | grep A1

as expected, does not yield results.


on GP4, executing:

gradle dependencies | grep A1

actually shows it is there.

I would expect A1 not to be in the dependencies tree of GP4.

Does that scenario is a problem?

If not, can anyone please elaborate on the reason behind this behavior?



(Szczepan Faber) #2

How do you exchange the artifacts between projects? E.g. how do you publish and consume the artifacts?

My theory would be: when you publish GP3, the published library metadata for does contain the exclusion you have declared in the dependencies section.

Hope that helps!

(ohad.raz) #3


You are right; the pom file does not contains the exclusions element.

My pom task looks as follows:

task pom {
   description = 'Generates POM file for the artifact.'
     outputs.file pomFile
     doLast {

(using plugins: java, eclipse, and maven)

Any reason why it is not there (i.e., why the exclusions element in the _pom_file)?

(Terence Kent) #4

(Just in case somebody happens across this post while troubleshooting a related issue, as I did)

As of gradle 1.10 (and perhaps earlier) exclusions are included in the generated POMs.