Xelian
Xelian

Reputation: 17228

Exclude files from FileTree in Gradle

I want to exclude src\main and src\test files from src

FileCollection files = 
project.fileTree(/src/).minus(project.fileTree(/src\main/)).minus(project.fileTree(/src\test/))

How can I exclude this directories without double minus usage?

Upvotes: 9

Views: 24103

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123986

The idiomatic way to exclude subdirectories from a FileTree is:

def files = fileTree("src").matching {
    exclude "main", "test" // relative to the file tree's root directory
}

PS: Instead of .minus, you can use -.

Upvotes: 17

Related Questions