Search code examples
javagradlejunitdependencies

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:

+--- 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. Also, I don't want a JUnit dependency within my business logic. So it needs to be excluded. As a gradle newbie I'm having difficulties to find a solution. 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. But in the dependency tree I still see the dependency. So obviously it's not working. Any ideas?


Solution

  • Ok, answer was easier than I thought:

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