[GRADLE-952] JUnit on compile class path doesn't make it to testRuntime class path Created: 01/Jun/10  Updated: 04/Jan/13  Resolved: 24/Nov/10

Status: Resolved
Project: Gradle
Affects Version/s: 0.9
Fix Version/s: 0.9-rc-1

Type: Bug
Reporter: Peter Niederwieser Assignee: Adam Murdoch
Resolution: Fixed Votes: 0

Issue Links:
Related
Related to GRADLE-1037 Provide conflict resolution for depen... Resolved

 Description   

In the spock-specs project I've observed the following: If I put JUnit 4.8.1 on the compile class path, tests are run with an older version of JUnit (not sure where that version comes from), resulting in some failing tests. Only if I put JUnit 4.8.1 on the testCompile class path does it make it to the testRuntime class path. For more information, see this thread on the gradle-user list: http://old.nabble.com/Compile-dependencies-no-longer-on-test-runtime-class-path--ts28723918.html

Problem exists in 0.9-preview-1 and preview-2, but not in 0.8.



 Comments   
Comment by Adam Murdoch [ 13/Jul/10 ]

The basic problem here is that jmock-junit4 happens to drag in junit-dep 4.4, and this is leading to a conflict with junit. Normally, Gradle's conflict resolution ensures that exactly one version of a dependency ends up in a classpath, but in this case, Gradle has no way of knowing that junit and junit-dep happen to include the same classes. And so, they are both included in the classpath.

This happens to work with Gradle 0.8, because it adds inherited dependencies to a classpath before the direct dependencies, and so junit ends up in the classpath before junit-dep. In 0.9, this order has been swapped, so that inherited dependencies are added after the direct dependencies, and so junit-dep ends up in the classpath before junit and the tests fail.

I think the real problem here is that there is no way to specify that junit implies junit-dep (particularly given that the dependency meta-data happens to come from a pom.xml in maven central) so that Gradle conflict resolution can figure out that it only needs to include junit.

Comment by Adam Murdoch [ 15/Jul/10 ]

Another work around is to exclude junit-dep from the dependencies of jmock_junit4:

dependencies {
    testCompile (jmock_junit4) { exclude name: 'junit-dep' }
}
Comment by Adam Murdoch [ 15/Jul/10 ]

We will address this problem as part of GRADLE-1037.

Generated at Wed Jun 30 11:43:06 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.