I have a plugin which includes a jar file as dependency of compile configuration, which I cannot use in my testRuntime configuration. In testRuntime it should be replaced by a maven dependency.
Here is a snippet from the plugin including the jar file
project.dependencies {
compile project.files("${javacardHome}/lib/api.jar")
}
Than I add another dependency containing the same classes, in order to mock the jar for tests.
dependencies {
testCompile ‘com.licel:jcardsim:2.2.2’
}
And from my test I get the following classpath:
/myproject/build/classes/test:/myproject//build/resources/test: … :/somefolder/lib/api.jar: … :/gradlecache/jcardsim-2.2.2.jar
Which than causes may test to fail. I tried to reoder the classpath, but couldn’t succeed.
I modified the class path of the test task by adding:
test {
classpath = project.sourceSets.test.runtimeClasspath.filter { !it.path.endsWith(“lib/api.jar”) }
}
But now my gradle does behave very oddly. First of all it complains from time to time about not beeing able to find the test classes (which also seem not be generated unless I run compileTest manually. Also I can’t load any ressource files form test/ressources.
I investigated a bit more and it seems if I alter the class path the test task completly forgets about its dependencies. So my current fix looks like this:
// alter the class path as needed
sourceSets {
test {
runtimeClasspath = project.sourceSets.test.runtimeClasspath.filter { !it.path.endsWith(“lib/api.jar”)
}
}
}
// set up dependencies again
test {
dependsOn(testClasses)
}