如何排除Gradle中的传递jar依赖项? [英] How to exclude transitive jar dependency in Gradle?

查看:162
本文介绍了如何排除Gradle中的传递jar依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目依赖于依赖项A和依赖项B.

依赖项A也依赖于依赖项B,但是它依赖于不同版本。



问题在于项目A的 build.gradle 依赖项B作为jar直接使用file和fileTree方法包含在内:

 依赖关系{
编译fileTree(dir:'libs',include:['* .jar'])
编译文件('libs / B.jar')
}

我的项目的 build.gradle 看起来像这样:

 依赖关系{
compile'c​​om.B :B:myvesion'
compile('com.A:A:theirversion'){
排除模块:'B'
}
}

但是我的编译失败,出现这个异常:

 任务执行失败':myproject:transformDexArchiveWithDexMergerForDebug'。 
> com.android.build.api.transform.TransformException:com.android.dex.DexException:多个dex文件定义Lcom / B / someclass;

我想排除 jar 版本B从我的项目中使用我的版本。我该怎么做呢?看起来像 exclude 指令在我的情况下不起作用。

解决方案

你无法为jar文件做这件事。

您可以排除传递依赖关系(在pom文件中描述)。 jar文件不是传递依赖项。


My project depends on dependency A and dependency B.

Dependency A also depends on dependency B, but a different version of it.

The problem is in project A's build.gradle dependency B is included as a jar directly using the file and fileTree methods:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/B.jar')
}

My project's build.gradle looks like this:

dependencies {
    compile 'com.B:B:myvesion'
    compile('com.A:A:theirversion') {
        exclude module: 'B'
    }
}

But my build fails with this exception:

Execution failed for task ':myproject:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lcom/B/someclass;

I want to exclude the jar version of B from my project and use my version. How do I do this? Seems like the exclude instruction doesn't work in my case.

解决方案

You can't do it for the jar files.

You can exclude transitive dependencies (described in the pom file). The jar file is not a transitive dependency.

这篇关于如何排除Gradle中的传递jar依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆