Copy task doesn't copy files starting with a dot

Hi. I’m trying to copy some git files that start with a dot (like .gitignore) with a copy task.
But they get simply ignored. I’m trying like this:

task copyTemplateFiles(type: Copy, dependsOn: initGradle) {
    from (projectDir) {
        include ".gitattributes"
        include ".gitignore"
    }
    
    from "template"
    
    into destiontionDir
}

And also like this:

task copyTemplateFiles(type: Copy, dependsOn: initGradle) {
    from (projectDir) {
        include "**/*.gitattributes"
        include "**/*.gitignore"
    }
    
    from "template"
    
    into destiontionDir
}

But nothing works

The underlying Ant class that the Gradle Copy task delegates to has default excludes. It’s not every hidden file, but the ones that Ant expected were probably present incidentally, not part of the source of your project that you actually want to work with. See this Gradle issue for some comments on working around it: [#GRADLE-1883] Provide a way to disable the default excludes on a FileTree without disabling the global excludes for all PatternSet instances

2 Likes

Thank you a lot! The first comment as a decent solution.

1 Like

The link is dead. Could any of you write the solution here ?

Issue tracking moved to GitHub, so many of the original JIRA links don’t work, but you can still search for just about any Gradle issue by ID, such as GRADLE-1883 and get the original result from the archive.

However, at this point, the documentation has the official supported method: Working with Files: Change Default Excludes. I believe the work-around in the issue should trigger a warning now.