8

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?

ditkin
  • 6,774
  • 1
  • 35
  • 37
Xelian
  • 16,680
  • 25
  • 99
  • 152

1 Answers1

16

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 -.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • I was wandering can pass ArrayList ["src/main","src/test"]on FilerTree or something like that? – Xelian Feb 21 '14 at 18:43
  • 1
    If you have multiple roots, you need to create multiple file trees and combine them with `+`. For users of a task or extension it can be more convenient if the task/extension accepts an `Object` (or `List`) representing the root directory(s), and converts to a FileTree internally. For API details, see the [Gradle Build Language Reference](http://gradle.org/docs/current/dsl/index.html) (e.g. `Project#fileTree`) and the Javadoc/Groovydoc. – Peter Niederwieser Feb 21 '14 at 19:04