Copy "git" specific files

I need to copy some github project to another location. The other-folder ends up without the .git and .gitignore files.

 task('myCopyTask', type: Copy) {
    from ("github-source-code")

I fixed the problem with .git folder adding a specific task for it.
I am fixing the problem .gitignore files renaming them before and after the copy, but isn’t there an easy way to do it?

You can rename file using rename(String sourceRegEx, String replaceWith).

task myCopyTask(type: Copy) {
    into 'other-folder'
    from ('github-source-code') {
        rename '*gitignore', 'other-name'

For more information is available Copy DSL.

The issue is the file “.gitignore” gets ignore, (no pun). The copy task doesn’t copy it. Is there a way to copy the file without renaming it?

It’s a feature we inherited from Ant’s default excludes.

You could try:"**/.gitignore")

This affects all copy tasks. You can see all the defaults here:

1 Like

This issue is mentioned in GRADLE-1883 and also contains a possible solution that would allow you not to rename.

If you want to use this code, you should be able to remove the second line in the doFirst. This commit removed the need to add back a default exclude, mentioning the same use case as shown in GRADLE-1883.

1 Like