【问题标题】:Gradle dependency exclusionGradle 依赖排除
【发布时间】:2015-06-23 17:51:02
【问题描述】:

我有一个项目 A 和一个项目 B。项目 A 也是一个被其他项目使用的核心项目。这是他的build.gradle 依赖项:

dependencies {
    compile 'com.android.support:support-v4:22.0.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile('org.simpleframework:simple-xml:2.7.1') {
        //http://stackoverflow.com/a/19455878/1423773
        exclude module: 'stax'
        exclude module: 'stax-api'
        exclude module: 'xpp3'
    }

    compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'org.apache.httpcomponents:httpmime:4.5'
}

因为它是一个具有最新依赖版本的 核心 项目,所以很有意义。项目 B 使用了一个使用 httpcore-4.2.4.jar 的依赖项,如果我不将我的 core 项目 build.gradle 修改为:

dependencies {
    ...    
//    compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'org.apache.httpcomponents:httpcore:4.2.4'
    compile('org.apache.httpcomponents:httpmime:4.5') {
        exclude module: 'httpcore'
    }
}

这是我想避免的,因为我不想更改我的核心项目build.gradle
这种情况的最佳解决方案是什么?如果我从我的其他依赖项中删除/排除 .jar 会起作用吗?如果是这样,我该如何删除它?我试过exclude module/group 但没有任何运气。我想到的是Chapter 56. Multi-project Builds(我还没有读过),但我想避免在我的核心项目中为每个非核心项目使用不同的gradle.build 文件。

我的项目B冲突依赖:co.realtime:messaging-android:2.1.40

谢谢。

【问题讨论】:

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


    【解决方案1】:

    我找到了,它一直在我面前……

    所以在我的项目 B 中,我只需要遵循我在 core 项目中使用的相同方法:

    compile (project(':submodules:MyCoreProject')){
            exclude module: 'httpcore'
            //co.realtime:messaging-android:2.1.40
            //uses 'org.apache.httpcomponents:httpcore:4.2.4'
    }
    

    现在是我的核心项目:

    dependencies {
        compile 'com.android.support:support-v4:22.0.0'
        compile 'com.google.code.gson:gson:2.3.1'
        compile('org.simpleframework:simple-xml:2.7.1') {
            //http://stackoverflow.com/a/19455878/1423773
            exclude module: 'stax'
            exclude module: 'stax-api'
            exclude module: 'xpp3'
        }
    
        compile 'org.apache.httpcomponents:httpcore:4.4.1'
        compile 'org.apache.httpcomponents:httpmime:4.5'
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 2021-12-05
      • 2020-07-27
      • 1970-01-01
      • 1970-01-01
      • 2016-11-19
      相关资源
      最近更新 更多