1

Consider such a situation: there's a big project, which takes tremendous time to compile and I'm having it's resulting artifacts as separate files (jar).

I want to run the unit tests on this project without compiling and jar-ing project itself, so I need to remove dependency on compileJava task, but this task is not in the dependsOn list of test task.

dependsOn property of test task contains only some [file collection] and if I'm printing this FileCollection.files, I'm getting the list of files and directories, which include .../build/classes/main. I think, after removing this entry, I'll get success in removing dependency on compileJava (as I understood, .../build/classes/main is just the result of running compileJava and that's why compileJava appeared). But I just don't understand, how to remove this entry.

By the way, in this case there's no problem of adding this jar to classpath, so that's not an issue.

I'm using Gradle 1.8. Thanks.

Dmitry Ginzburg
  • 7,391
  • 2
  • 37
  • 48
  • No idea how it would work well? If You don't compile sources before executing tests there'll be stale data. How would tests be reliable? – Opal Jun 20 '14 at 09:06
  • 2
    @Opal The case is explained (I think) clearly in the post: just consider this jar is downloaded from local network and I need to run unit tests on it. – Dmitry Ginzburg Jun 20 '14 at 10:54

1 Answers1

1

compileJava will be up-to-date if nothing has changed, and jar isn't depended upon by test. If you nevertheless want to add the ability to run tests against a downloaded Jar, declare another Test task. (Reconfiguring test.classpath should work as well, but seems less desirable.)

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • In this case there's many already configured `test` tasks in the existing project (actually, multi-project), so I want to reuse them, not add the new `Test` tasks. Why do you think, reconfiguring `classpath` will fix the issue? Is this causing some change of source sets? – Dmitry Ginzburg Jun 21 '14 at 11:11
  • The `java` plugin doesn't configure any explicit task dependencies for `Test` tasks. Instead, task dependencies are inferred from inputs such as `classpath`. Instead of reconfiguring `test.classpath`, you could also consider to reconfigure `sourceSets.test.compileClasspath` or `sourceSets.test.runtimeClasspath`. – Peter Niederwieser Jun 21 '14 at 17:45
  • Hmm, I've just tried to remove dependency with `test.classpath = test.classpath.filter { file -> !file.absolutePath.contains('main') }` and got no success, because *suddenly* `compileTestJava` was removed from `test` dependency, why can it be? – Dmitry Ginzburg Jul 04 '14 at 13:03