The docs say <https://docs.gradle.org/current/user...
# community-support
a
The docs say "any exclusion pattern overrides any inclusions". The below code has an exclusion for any file in a
b/
directory. So why does
filteredFiles.asPath
contain
b/test2.txt
?
Copy code
val someFiles = objects.fileCollection()
  .from(
    "a/test1.txt",
    "a/test1.dat",
    "b/test2.txt",
    "b/test2.dat",
  )

someFiles.forEach {
  it.parentFile.mkdirs()
  it.writeText(it.name)
}

val filteredFiles = someFiles.asFileTree.matching {
  include("**.txt")
  exclude("**/b/**")
}

println("filteredFiles: ${filteredFiles.asPath}")
v
Your problem is not, that exclude does not win over include, but that your assumptions about what your pattern is applied on is wrong. As you add
b/test2.txt
to the file collection, that is the base path and so your pattern is only applied to
test2.txt
which makes the include work, but the exclude not. Even if you would have
.from("a", "b")
it would not be different as still
a
and
b
are the root paths and the patterns start after that. If you would have
.from(".")
, then the patterns would work, but also
b/**
or even
b/
would be enough as the matched path starts with
b
, unless you really also want to match deeper `b`s. If you want to match on the full path, I think using
exclude { ... }
should work.