Examples of copy from multiple sources, to relative destination paths, with optional filtering, all in the war block?

Is there a good example of a war block that specifies multiple “from” locations, along with multiple relative destination locations, with optional filtering? I believe it’s the case that I can specify multiple “from” clauses, but I think I would have to have an “eachFile” to check each file name to decide what relative folder in the WAR to copy the file to.

The War task uses a CopySpec to specify what should be copied where. You can find an example in the DSL guide for the Copy task.

Looks like the DSL Reference doesn’t specifically show an example for this case.

war {
    from('src1') {
        into 'dest1'
    }
    from('src2') {
        into 'dest2'
    }
}

Interesting. What I often find confusing about all of these docs is that many of these methods can be called from inside the closures passed to other methods, but the docs don’t give any clue when this would be the case or not. I would suggest changes if I knew what the actual rules were.

The other confusing thing in this case is the “into” method and the “destinationDir” property. When should or can one be used in place of the other?

In this case I am calling this method, which takes a source path and a Closure, which configures a child CopySpec. There’s nothing dynamic or magic here, into() is simply a method on the child CopySpec. We can nest these as deep as we want creating a hierarchy of CopySpecs.

The destinationDir property is specific to archive tasks. It is the directory that the archive (zip, tar, war) will be placed. On the other hand, into() specifies where files should be copied inside the archive, relative to the root.