我有一个项目 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
会起作用吗?如果是这样,我该如何删除它?我尝试过排除模块/组
但没有任何运气。我想到的是Chapter 56. Multi-project Builds (我还没有读过)但我想避免在我的核心项目中为每个非核心项目使用不同的 gradle.build
文件。
我的项目B冲突依赖:co.realtime:messaging-android:2.1.40
谢谢。
最佳答案
我找到了,它一直在我面前......
因此,在我的项目 B 中,我只需遵循我在核心项目中使用的相同方法:
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'
}
关于android - Gradle 依赖排除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31009965/