How can I share dependency declarations with exclusions among projects?


(ray.tang) #1

Hi:

I am new to gradle and wondering what’s is the best practice trying to setup exclusions like maven builds in gradle in large complicated classpath?

So the parent build.gradle looks like this. … libraries = [

‘cxf’…

‘credit’…

‘commons’:…

‘others’:[…, ‘xxx.xxx:xxx’, …]

]

The child project looks like this

dependencies {

compile libraries.‘credit’, libraries.‘cxf’, libraries.‘commons’, libraries.‘others’

testCompile libraries.‘credit’ }

The issue is that I need to set up exclusions for xxx and currently I can’t seem to find any doc showing how to do this.

Many Thanks.


(Peter Niederwieser) #2

Assuming you want to share the exclusions just like the libraries:

libraries = [
  commons: dependencies.create("commons:commons:1.0") {
    exclude group: "org.springframework"
    exclude module: "hibernate-core"
  }
]

Another option is to exclude dependencies globally for one or all configurations:

subprojects {
  configurations.compile.exclude group: "org.springframework"
    configurations.all*.exclude module: "hibernate-core"
}

(ray.tang) #3

Great! Thanks a lot Peter.