How do I specify excludes when defining dependencies in an array?


(henrik) #1

I am trying to define my dependencies in my root build.gradle, like this:

ext.libs = [
    jersey_common: "org.glassfish.jersey.core:jersey-common:${versions.jersey}",
    jersey_servlet: [ "org.glassfish.jersey.containers:jersey-container-servlet:${versions.jersey}", {
        exclude group: 'javax.validation'
    }],
    jersey_server: "org.glassfish.jersey.core:jersey-server:${versions.jersey}",
]

Then I use them in my subprojects, like this:

dependencies {
    compile(
        libs.jersey_common,
        libs.jersey_servlet,
        libs.jersey_server,
   )
}

It doesn’t like the exclude syntax, though:

FAILURE: Build failed with an exception.
  * Where:
Build file '/path/to/build.gradle' line: 24
  * What went wrong:
A problem occurred evaluating project ':my-test'.
> Cannot convert the provided notation to an object of type Dependency: build_3lp20ohblpvfhdefqk7oi77ih6$_run_closure2@3c5614b2.
  The following types/formats are supported:

How do I specify the excludes properly?

( I was inspired by this post when I defined the excludes: http://gradle.1045684.n5.nabble.com/Multiproject-dependencies-using-Maven-style-dependencyManagement-tt3305232.html#a3385043 )


(Peter Niederwieser) #2
ext.libs = [
    jersey_servlet: dependencies.create("org.glassfish.jersey.containers:jersey-container-servlet:${versions.jersey}") {
        exclude group: "javax.validation"
   }
]

(henrik) #3

Thanks again! Impressively fast answer.