'gradle war CopySpec “add only” (no override)

I’m trying to set up the files that are copied to my war. The source directory has 2 directories, and some of the files below them should be added to the war. This works when the directories are distinct, but when the same sub-directory exist in both then the 2nd directory overrides the first. I would like the files from both to be included.

source files:

A/conf/foo/bar/a.txt
A/conf/foo/bar/b.txt
A/conf/hehe/hihi/c.txt
B/conf/foo/bar/d.txt
B/conf/foo/moo/e.txt
B/conf/asd/f.txt

What I tried is:

war {
    from('A') {
        include 'conf/foo/**'
    }
    from('B') {
        include 'conf/**'
    }
}

Expected: the following files are included in war:

conf/foo/bar/a.txt
conf/foo/bar/b.txt
conf/foo/bar/d.txt
conf/foo/moo/e.txt
conf/asd/f.txt

Actual: only the files from B are included:

conf/foo/bar/d.txt
conf/foo/moo/e.txt
conf/asd/f.txt

I prefer not to list all the sub-directories under A/conf/foo nor under B/conf, because there are lot of sub-directories, and also I’d like to find a future-proof solution, so when someone later adds another file or directory under either of them I’d like them to be copied to the war without the need to edit the build.gradle every time.



Solution 1:[1]

with paths for the folders A and B under the project-root as src/main/A, src/main/B

below produces as expected

war {
    from('src/main/A') {
        include 'conf/foo/**'
    }
    from('src/main/B') {
        include 'conf/**'
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PrasadU