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

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

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

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.

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.

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

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.

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.

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

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

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