Global excludes pollute generated POM

We have global excludes to get rid transient dependencies that are already part of Java 6 (e.g. jaxb-api):

  all*.exclude(group: 'javax.xml.bind', module: 'jaxb-api')

This works great except for the poms we generate. For every dependency in the pom, there are exclusion elements for all global excludes. I’m sure this fits well into how gradle works, but is probably never what one would like to see in the generated poms.

I think it would be great to have exclusions in the pom only if there is a transitive dependency which matches the global exclude. I’m not sure if this is something you would like to have in gradle. A workaround would therefore also be highly welcome (e.g. by customizing the pom).

Thank you for your help!

So the problem is that there’s too much information in the output pom.xml, huh? :slight_smile:

Take a look at the section in the user guide related to customizing the auto-generated pom.xml:

Hope that helps!

Hi Sczepan

Thanks for your answer. I tried to filter the unnecessary excludes from the pom, but I didn’t succeed. I tried to achieve what I wrote in the first post: I tried to remove all excludes from a dependency which didn’t apply (i.e. the dependency doesn’t depend on the excluded artifact).

The problem is, that when trying to achieve this in pom.whenConfigured, it was no longer possible for me to determine which transient dependencies a dependency originally had, because the excludes were already applied. I accessed the direct project dependencies through


and then went further to query these dependencies for their transient dependencies using


But as I said, these moduleArtifacts were already filtered, so they were useless for me to determine whether the exclusion is necessary on a given dependency.

I hope what I wrote makes sense. Feel free to correct me if I’m wrong or to ask a question to clarify things :slight_smile: Thanks again for your Help!

Oh I see. In that case you won’t be able to filter them out.

You might be able to achieve something similar without global excludes. Instead of a global exclude you might have a global check that fails early when dependency X is pulled in. The error message might say that one should apply an exclude on dependency Y to avoid pulling in X.

Hope that helps!

Thanks for the idea! It might really be an alternative to enforce these artifacts to be excluded where necessary.

Maybe one additional point why we used global excludes: At the moment we define the version numbers of all our dependencies in root build file, so we can manage them in one place. With maven we even managed the dependencies together with their exclusions in the parent pom (if the exclusions were applicable for all modules).

We haven’t found a possibility to do this in gradle so we worked around it by using global excludes. Or did we get it wrong?

When thinking about it, this is probably the root of our problem.

You can manage excludes (and any other dependency settings) in one place like this:

libs = [
  foo: dependencies.create("foo:foo:1.0") {
    exclude group: "bar"

Thank you very much for the solution Peter! That was exactly what I was looking for! It would be great to have this in the user documentation.

Thanks again to you both, and sorry for eating up your time…