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 then 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.

I can’t test it right now, but I think it may work if you include conf/foo/**/* and conf/**/*. I suspect it may work because the files are included instead of the directories.

Actually It works with the original version I tries, turns out the problem was that I had a typo in the relative path of A/

1 Like