sunleo
sunleo

Reputation: 10943

How to exclude a jar from gradle

I try to exclude a jar from gradle build but how to do that for my project part I am not clear.Below are the dependencies I have to exclude only geronimo-javamail_1.4_spec/1.7.1 jar because which gives error when I try to send mail.Please give your guidance to solve this.

    dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-batch")
    //compile("org.springframework.boot:spring-boot-devtools")
    compile('org.apache.commons':'commons-lang3':'3.5'){
                exclude module: 'geronimo'
    }
    compile group: 'org.apache.cxf', name: 'cxf-spring-boot-starter-jaxws', version: '3.1.10'
    compile group: 'org.apache.cxf', name: 'cxf-rt-ws-security', version: '3.1.10'
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

update:exclusion is not working

Upvotes: 7

Views: 37505

Answers (1)

OlgaMaciaszek
OlgaMaciaszek

Reputation: 3912

First of all, there is an issue with this statement:

compile('org.apache.commons':'commons-lang3':'3.5')

If you want to use the colon notation for a dependency, it has to be all in one String, like so:

compile('org.apache.commons:commons-lang3:3.5')

Also, you should probably use the full module name: module: 'geronimo-javamail_1.4_spec'.

Finally, geronimo-javamail_1.4_spec is a transitive dependency of more than one dependency in this setup, so you should exclude it everywhere where necessary one by one, or exclude it altogether like so:

configurations {
    all*.exclude module: 'geronimo-javamail_1.4_spec'
}

This should be added in your build.gradle file at the same level as the dependencies{} section, not within it, so the final code would look like this:

configurations {
    all*.exclude module: 'geronimo-javamail_1.4_spec'
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile("org.springframework.boot:spring-boot-starter-web")  
    compile("org.springframework.boot:spring-boot-starter-batch")
    //compile("org.springframework.boot:spring-boot-devtools")
    compile('org.apache.commons:commons-lang3:3.5')
    compile group: 'org.apache.cxf', name: 'cxf-spring-boot-starter-jaxws', version: '3.1.10'
    compile group: 'org.apache.cxf', name: 'cxf-rt-ws-security', version: '3.1.10'
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

Upvotes: 12

Related Questions