【问题标题】:How to exclude modules or groups in a jar from Gradle?如何从 Gradle 中排除 jar 中的模块或组?
【发布时间】:2016-02-13 18:02:13
【问题描述】:

我正在尝试编写一个 gradle 脚本,我想在其中忽略或排除 jar 文件中的某些模块或组。

我的代码:

dependencies {

    compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
    compile fileTree(dir: 'libs', include: ['*.jar'])     
    compile files('libs/test.jar')

  }

所以,我想从 test.jar 文件中排除“com.xyz.abc”,但我不知道如何编写脚本。

请告诉我,建议我一些好的解决方案。

【问题讨论】:

    标签: android android-gradle-plugin build.gradle


    【解决方案1】:

    尝试排除传递依赖,如here 所述:

    您可以通过配置或依赖排除传递依赖:

    示例 52.14。排除传递依赖

    build.gradle

    configurations {
        compile.exclude module: 'commons'
        all*.exclude group: 'org.gradle.test.excludes', module: 'reports'
    }
    
    dependencies {
        compile("org.gradle.test.excludes:api:1.0") {
            exclude module: 'shared'
        }
    }
    

    【讨论】:

    • 谢谢,这就是我要找的。再次感谢
    • 我自己尝试使用 exclude(),但使用编译文件: compile files ('libs/sshd-core-0.7.0.jar') { exclude module: 'mina-core' }。但是,我就是无法让它工作。编译jar时排除不工作吗??
    • @Rich 你找到解决方案了吗?我也是和你一样的意图来到这里的。
    • @GuilhermeSantos 你找到解决方案了吗?
    • exclude不能用compile filescompile fileTree,也许我们可以解压jar文件,删除它,然后压缩成新的纯jar~
    猜你喜欢
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-13
    • 2018-01-04
    • 2021-08-28
    • 1970-01-01
    相关资源
    最近更新 更多