java 如何从 gradle 中排除 jar

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43137738/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 07:07:57  来源:igfitidea点击:

How to exclude a jar from gradle

javagradle

提问by sunleo

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.

我尝试从 gradle 构建中排除一个 jar,但是如何为我的项目部分执行此操作我不清楚。以下是我必须仅排除 geronimo-javamail_1.4_spec/1.7.1 jar 的依赖项,因为当我尝试时会出现错误发送邮件。请指导您解决此问题。

    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

更新:排除不起作用

回答by OlgaMaciaszek

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'.

此外,您可能应该使用完整的模块名称:module: 'geronimo-javamail_1.4_spec'.

Finally, geronimo-javamail_1.4_specis 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:

最后,geronimo-javamail_1.4_spec在此设置中是多个依赖项的传递依赖项,因此您应该在需要的任何地方逐一排除它,或者像这样完全排除它:

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

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

这应该添加到您的build.gradle文件中,与该dependencies{}部分处于同一级别,而不是在其中,因此最终代码将如下所示:

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')
}