How to clear a FileTree? | Cannot cast object 'directory .... to class 'org.gradle.api.file.FileTree'


(Horcrux7) #1

With the follow code I receive the error: Cannot cast object ‘directory ‘…\build\classes\test’’ with class ‘org.gradle.api.internal.file.AbstractFileCollection$1’ to class ‘org.gradle.api.file.FileTree’

Any Idea how I can clear the FileTree before I add my own content.

Test coverage = task(type: Test) {}
    FileTree classes = coverage.getCandidateClassFiles()
    classes -= classes

(Peter Niederwieser) #2

What are you trying to achieve here? You shouldn’t have to modify that file tree directly.


(Horcrux7) #3

I want run a single junit test from a library jar. The junit tests of the current project was execute before.

In the mean time I have a solution. see my post at http://forums.gradle.org/gradle/topics/executing_a_single_junit_test_suite_programmatically_from_a_task

But independent of my solution the handling of the FileTree is not optimal in gradle.


(Peter Niederwieser) #4

But independent of my solution the handling of the FileTree is not optimal in gradle.

That’s too general a statement to discuss meaningfully. Not sure what you are trying to configure, but configuring ‘candidateClassFiles’ is likely the wrong approach.


(Horcrux7) #5

Ok, you are the boss. What is the right solution to set explicit the class names of some JUnit tests?


(Peter Niederwieser) #6

I suppose you mean to configure which test classes are to be executed? ‘test.include “org/MyTest.class”’ or ‘test.filter.includeTestsMatching “org.MyTest”’. See Gradle Build Language Reference for details.


(Horcrux7) #7

The test.include and test.includeTestsMatching has only an effect on classes inside of TestClassesDir. But we does not have a TestClassesDir. Our test classes are inside of an jar file.


(Peter Niederwieser) #8

The ‘Test’ task doesn’t currently support this. You’ll have to unzip the Jar file.


(Horcrux7) #9

Peter can you create a RFE (request for enhancement) for it or do you think this make no sense?


(Peter Niederwieser) #10

It does make sense. I’m pretty sure http://issues.gradle.org already has an issue for this. Perhaps you can double-check?