Hello, I have a "compile" task that contains the f...
# community-support
a
Hello, I have a "compile" task that contains the following code:
Copy code
source = fileTree("$projectDir").matching {
    include("$javaSourceDirName/**/*.java")
    excludedJavaFiles.forEach { exclude(it) }
}
This results in many errors such as:
Copy code
Cannot infer source root(s) for source `file 'C:\...\Blabla.java'`. Supported types are `File` (directories only), `DirectoryTree` and `SourceDirectorySet`.
This seems to disable incremental compilation. How can I fix this code snippet?
1
v
I doubt you can. The error says you must set directories but you try to set files. But you might be at an XY-problem. Take a step back. What is your use-case, what do you try to achieve?
a
I have a directory (
$projectDir
) which contains Java source files (in nested directories). I also have a list of excluded Java files. I want to set the source of this "compile" task to the Java source files minus the excluded Java files.
v
That's the Y problem, what is the X problem?
a
Well my goal is to compile a bunch of Java files whilst excluding some specific files.
v
But why? You are still at the Y, tell us the X please.
Or well, just configure the excludes on the compile task instead of trying to configure a filetree, but really why do you want to do that?
1
Copy code
tasks.compileJava {
    exclude(...)
}
thank you 1
1