I came across a very subtle and difficult-to-debug error that turned out to be caused by Gradle using different versions of a dependency for compile and testCompile. I didn’t think that should be possible, but I suppose I can see where conceptually they are independent tasks. The relevant part of my build.gradle dependencies section looked like this:
compile 'com.company.packageA:dependencyA:1.0' testCompile 'com.company.packageB:dependencyB:2.0'
dependencyB pulled in version 2.0 of dependencyA as a transitive dependency, which resulted in testing being done with a different version of dependencyA than was compiled and packaged.
Is there any way I can prevent this situation from occurring, or at least warn me when it does? From conversations with my teammates, apparently this has been the unfindable root cause of more than one hacky workaround over the years. I’d like to avoid that in the future.
I checked the documentation here, and couldn’t find anything that seemed relevant to my situation.