Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle global exclude

Tags:

gradle

How can I exclude:

com.sun.xml.bind:*:*

from all projects, all configurations, regardless of version?

I need to replace them with:

'org.glassfish.jaxb:jaxb-xjc:2.2.11'
'org.glassfish.jaxb:jaxb-runtime:2.2.11'
...

in accordance with:

https://github.com/jacobono/gradle-jaxb-plugin/issues/15

....hmmm... Is there a way to replace them in one step?

like image 881
user447607 Avatar asked Jan 21 '16 15:01

user447607


People also ask

What is exclude in Gradle?

When you specify a dependency in your build script, you can provide an exclude rule at the same time telling Gradle not to pull in the specified transitive dependency. For example, say we have a Gradle project that depends on Google's Guava library, or more specifically com.

How do I exclude tasks in Gradle?

Using Command Line Flags Task :compileTestJava > Task :processTestResources NO-SOURCE > Task :testClasses > Task :test > ... To skip any task from the Gradle build, we can use the -x or –exclude-task option. In this case, we'll use “-x test” to skip tests from the build.

How do you resolve transitive dependencies in Gradle?

A variant of a component can have dependencies on other modules to work properly, so-called transitive dependencies. Releases of a module hosted on a repository can provide metadata to declare those transitive dependencies. By default, Gradle resolves transitive dependencies automatically.


1 Answers

According to the Gradle User Guide on Dependency Management explains, you can exclude all versions of a given dependency from all configurations:

configurations.all {
    exclude group: 'com.sun.xml.bind'
}

Then just add the glassfish dependencies (may need compile instead of runtime configuration)

dependencies {
    runtime 'org.glassfish.jaxb:jaxb-xjc:2.2.11'
    runtime 'org.glassfish.jaxb:jaxb-runtime:2.2.11'
}

Alternatively, you could try dependency substitution, but that might be hairy.

like image 113
Eric Wendelin Avatar answered Oct 01 '22 06:10

Eric Wendelin