简体   繁体   English

如何在 Gradle 中排除 JUnit 作为传递依赖

[英]How to exclude JUnit as transitive dependency in Gradle

I have noticed that I have an unwanted transitive dependency on junit:junit-dep:4.11 in my build.gradle file:我注意到我在 build.gradle 文件中对junit:junit-dep:4.11有一个不需要的传递依赖:

+--- com.myprojectabc-cmis:0.3.1
|    \--- org.alfresco.cmis.client:alfresco-opencmis-extension:1.1
|         \--- junit:junit-dep:4.11
|              \--- junit:junit:4.11
|                   \--- org.hamcrest:hamcrest-core:1.3

This JUnit dependency is a potential source of conflict, since I normally use the version 4.12 in my project.这个 JUnit 依赖是潜在的冲突源,因为我通常在我的项目中使用 4.12 版本。 Also, I don't want a JUnit dependency within my business logic.此外,我不希望在我的业务逻辑中存在 JUnit 依赖项。 So it needs to be excluded .所以需要excluded As a gradle newbie I'm having difficulties to find a solution.作为 gradle 新手,我很难找到解决方案。 I've read the docs and also looked into this and this and still couldn't figure out the right way to do it.我已经阅读了文档,也研究了这个这个,但仍然无法找到正确的方法。 I've also tried this:我也试过这个:

compile('com.myprojectabc-cmis:0.3.1') {
 exclude group: 'junit', module: 'junit:4.11' 
}

and this:和这个:

compile('com.myprojectabc-cmis:0.3.1') {
   exclude group: 'junit', module: 'junit-dep:4.11' 
}

Gradle loads without problems when I make this change.当我进行此更改时,Gradle 加载没有问题。 But in the dependency tree I still see the dependency.但是在依赖树中我仍然看到依赖。 So obviously it's not working.所以显然它不起作用。 Any ideas?有任何想法吗?

Ok, answer was easier than I thought:好的,答案比我想象的要容易:

        exclude group: 'junit', module: 'junit-dep'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM