coderatchet
coderatchet

Reputation: 8420

multiple copyspecs in a single copytask in gradle (nested copyspecs)

I have an ear file that will have root deployments (deploy configuration), lib deployments (earlibs configuration) and an additional custom utilJars configuration that I want to place in a utilJars folder at the root of the ear. I am aware that the first two configurations are automatically handled by the Ear task.

How can I add an additional CopySpec to the Ear task (or any AbstractCopyTask for that matter) to handle the third configuration?

Upvotes: 2

Views: 968

Answers (1)

coderatchet
coderatchet

Reputation: 8420

My understanding of copy specs was erroneous. Instead of copyspecs existing side by side, they exist in a hierachy, as explained in section 16.6.3 of the gradle user guide.

thus additional copy specs may be 'nested' within the root specification of the task. These nested specs inherit the parent specs unless otherwise specified:

e.g. in the following spec, the root spec contains an into, exclude and from spec. in the from spec, there is a nested include spec. This spec does not overwrite anything from the root spec, and the root spec does not see it. The into spec does however overwrite the from copyspec and thus will copy everything from the configuration 'runtime' into the folder libs but not anything from the src/dist folder.

task nestedSpecs(type: Copy) {
    into 'build/explodedWar'
    exclude '**/*staging*'
    from('src/dist') {
        include '**/*.html'
    }
    into('libs') {
        from configurations.runtime
    }
}

I hope this helps someone else :)

Upvotes: 3

Related Questions