Skip to content

fix: expand a directory passed to targetExclude into the files under it - #3032

Open
jjh75607 wants to merge 2 commits into
diffplug:mainfrom
jjh75607:fix/target-exclude-directory
Open

fix: expand a directory passed to targetExclude into the files under it#3032
jjh75607 wants to merge 2 commits into
diffplug:mainfrom
jjh75607:fix/target-exclude-directory

Conversation

@jjh75607

Copy link
Copy Markdown
Contributor

Fixes #2667

parseTargetIsExclude has no branch for Gradle's directory types, so a Directory,
DirectoryProperty, or Provider<Directory> fell through to getProject().files(target)
and became a collection holding the directory itself. target.minus(targetExclude) then
removed nothing, so excluding a directory silently did nothing.

An excluded directory now contributes the files under it through getAsFileTree(). That
keeps the expansion lazy, which matters here: resolving the collection while the extension
is being configured would freeze the directory listing before the build has produced
anything.

This is deliberately limited to targetExclude. The String branch above adds .git,
.gradle, and build directories to the excludes when it is including, and a bare directory
tree carries none of that, so letting target accept a directory would start formatting
build output and .git contents. The branch already treats including and excluding
differently for the same reason.

One note on the reproduction. The example in the issue uses layout.buildDirectory, and
with a **/-prefixed string target that looks like it already works, because the String
branch excludes build directories on its own. The scala block in the report has a
src/**-style default target, where nothing masks it. The tests use a generated directory
to stay out of the way of that automatic exclusion.

Tests cover Directory, DirectoryProperty, Provider<Directory>, and one run with the
configuration cache enabled. All four fail before the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow targetExclude to be passed a directory (Directory, DirectoryProperty, Provider<Directory>, etc.)

1 participant