vach
vach

Reputation: 11377

Gradle exclude group from dependant subproject

Given a gradle project A having a dependency on project B (no common parent)

compile project('B'){
    exclude group: 'org.slf4j'
}

how do we exclude transitive dependency group from a project we depend upon? (this piece of script will fail as there is no exclude for compile projet(..))

and more general question : is there an elegant way to exclude a particular group from all dependancies except if its a first level dependency?

for example we may have a bunch of libraries, and each may declare its logging environment, but by excluding all known groups of slf4j, its implementations and declaring specific version, we would ensure we don't have any version conflicts and would control version on module level.

Upvotes: 1

Views: 1852

Answers (1)

Alla B
Alla B

Reputation: 676

Here is an example from the Gradle documentation of how to exclude a transitive dependency (I guess that is what you meant by "except if its a first level dependency") on project level:

configurations {
    compile.exclude module: 'commons'
    all*.exclude group: 'org.gradle.test.excludes', module: 'reports'
}

See 52.4.7. Excluding transitive dependencies here

You can either specify the dependency directly with the desired version or use a forced version resolution strategy

Upvotes: 1

Related Questions