Deploy EAR exploded

When I deploy an EAR (that just contains WARs) to my local application server, I would like to skip the war tasks and deploy everything in exploded form.

I have managed to deploy the EAR in exploded form, but the war tasks are still running and thus I do not gain the speed-up I intendend.

task deploy(type: Sync) {
    with ear
    into 'C:/path/to/server/deployments/'
    exclude '**/*.war'
    def deps = configurations.deploy.getAllDependencies().withType(ProjectDependency)
    deps.each { dep -> 
        into(dep.dependencyProject.war.archiveName) {
            with dep.dependencyProject.war 
        }
    }
}

What is the best way to not trigger the war tasks?

tasks.withType(War).all { it.enabled = false }

Hi Lance. Thanks for the quick answer. Of course that would disable the war tasks. Unfortunately your approach would disable the war task completely. And I still need them to work in other cases. I just want to skip them, when i run the deploy task.

gradle.taskGraph.whenReady { TaskExecutionGraph g ->
   if (g.hasTask(deploy)) {
      tasks.withType(War).all { it.enabled = false }
   }
}

A slightly more concise alternative to @Lance_Java’s example.

tasks.withType(War) {
  onlyIf { !gradle.taskGraph.hasTask(deploy) }
}
1 Like

Yep, that solves my problem. Thank you guys!