How to automatically create exploded war, without invoking a seperate task

I’d like to be able to explode a war immediately after Gradle creates it. I know I can do this with the following:

task explodedWar(type: Copy) {
    into "$buildDir/exploded"
    with war
}

That works, but requires me to call the explodedWar task explicitly from the command-line. Is there a way to attach this directly to the war task, so it happens automatically? Something like:

war.doLast {
 explodedWar.execute()
}
  task explodedWar(type: Copy) {
    into "$buildDir/exploded"
    with war
}

I believe explicitly calling execute() on a task is discouraged, and this gives me an error anyway:

“The task artifact state cache (C:\temp\gradle-test\.gradle\1.0-milestone-9\taskArtifacts) has not been locked.”

Any suggestions?

1 Like

The explodedWar task does not explode the war file. Instead it reuses the specification of the war task (that defines which files are part of the archive) and copies them to a defined directory (in your case $buildDir/exploded.

So if you would like to have an explodedWar everytime you create the war, you can just set a dependency between those tasks:

war.dependsOn explodedWar

regards, René

1 Like

Thanks, that makes sense.