[GRADLE-3182] exclude ('*') in FileCollection excludes too much Created: 16/Oct/14  Updated: 18/Nov/16  Resolved: 18/Nov/16

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Gradle Forums Assignee: Pepper Lebeck-Jobe
Resolution: Duplicate Votes: 1


 Description   

Using Gradle 2.1 I observed the following inconsistency between the include and exclude options on FileCollections.

Given the following file structure

files/ignoreMe.txt
files/com/company/foo.class
files/org/group/bar.class

I tried creating a FileTree including all files, except those within the root of the source folder.

fileTree('files') {
exclude ('*')
}

which I would expect to contain all files but ignoreMe.txt. Instead it contains no files at all, acting as if '**' was defined. At the same time using the same pattern in include works as expected:

fileTree('files') {
include ('*')
}

As this FileTree contains only ignoreMe.txt.

The expected behavior can be described using this work-around:

fileTree('files') {
exclude { FileTreeElement element ->
!element.directory && element.relativePath.segments.length == 1
}
}



 Comments   
Comment by Pavel F [ 14/Apr/15 ]

Exactly the same exclude behavior for copy task execution as well:

task testCopy(type: Copy) {
    into 'some-target-folder'
    exclude '*'
    from 'files'
}

Although, it is different for include copy behavior:

task testCopy(type: Copy) {
    into 'some-target-folder'
    include '*'
    from 'files'
}

This case 0-level files copied (as expected) and also empty 1st-level dirs (not expected). Please see target dir content sample:

ignoreMe.txt
com/ <---- empty folder
org/ <---- empty folder

If this is the case - let me try to fix "exclude" issue first (may I assign issue?). And then, if required and not included, let`s raise and solve "include" issue

Comment by Stefan Oehme (Inactive) [ 11/Jan/16 ]

We decided not to change this behavior, as it would silently break existing builds.

We should document the current behavior instead.

Comment by Pepper Lebeck-Jobe [ 02/Feb/16 ]

We have changed the decision so that we will change this behavior. There is a pending pull request which will correct the behavior. We are going to update the release notes to suggest that the change may break existing builds.

Comment by Pepper Lebeck-Jobe [ 01/Mar/16 ]

The fix for this issue caused a regression in how include "*" worked and had to be reverted. Hopefully, we can get this fixed again in the future.

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Pepper Lebeck-Jobe [ 18/Nov/16 ]

Closing in favor of: https://github.com/gradle/gradle/issues/895

Generated at Wed Jun 30 12:42:08 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.