How to build an exploded ear containing exploded wars?

Our ear application is basically configured like this:

dependencies {
    earlib project(path: ":web", configuration:'compile')
    earlib project(path: ":webservices", configuration:'compile')
    deploy project(path: ":web", configuration: "archives")
    deploy project(path: ":webservices", configuration: "archives")
}

ear {
    archiveName = "app.ear"
    appDirName = "EarContent"
    duplicatesStrategy = EXCLUDE
    excludes = ['lib']
    generateDeploymentDescriptor = false;
}

My aim is to build an exploded ear using this code:

task explodedEar(type: Sync) {
    group = "build"
    into "${ear.destinationDirectory.get().asFile.absolutePath}/exploded/${ear.archiveFileName.get()}"
    with ear
}
ear.dependsOn explodedEar

Using this approach the ear is exploded. But the two war files (web, webservices) are simply copied to the exploded directory without being exploded themselves.

How can I achieve that the exploded ear contains the exploded (e.g. unpacked) war files?

Did you find a solution for this? Same problem here :frowning:

Unfortunately not :slightly_frowning_face:

I guess you could add a doLast action that iterates over the wars and explodes them using something like:

sync {
    from(zipTree(theWarHere))
    into(explodedLocation)
}

I have to explain it to you why I’m trying to do that.
We are currently not able to use hot deploying (Update Resources) with IntelliJ.
So we have to restart the application server after each change in e.g xhtml (JSF) or CSS file.
I found a solution for the ear plugin. With the following code I get the ear plugin to use the exploded war file.

war build.gradle

apply plugin: "war"

configurations {
    exploded
}

dependencies {
...
}

war {
    from "/WebContent"
}

task explodeWar(type: Sync) {
    into "$buildDir/libs/${war.archiveFile.get().asFile.getName()}"
    with war
}

war.dependsOn explodeWar

artifacts {
    exploded file("$buildDir/libs/exploded"), { builtBy explodeWar }
}   

ear build.gradle

...
dependencies {
    deploy(project(path: ":ViperNGUiWeb", configuration: "exploded"))
}
...

But that generates a crazy configuration in IntelliJs artifact configuration.
exploded.jar and the bunch of classes and xhtmls files are wrong here.

So IntelliJ does not recognize file changes correctly and does not update the resoruces :frowning:

my solution was to have a second task explodedWar

war {
    archiveBaseName  = 'yourWar'
    from 'src/main'
}

task explodedWar(type: Sync) {
    into "${buildDir}/libs/exploded/yourWar.war"
    with war
}

then in my ear task, I check for a command line argument to determine if it is exploded or not:

  def isDeployment = project.getProperties().get("isDeployment")


    if (isDeployment) {
        into ("") {
            from war
        }
    } else {
        into ("yourWar.war") {
            from explodedWar
        }
    }

currently I have one build.gradle file but I am trying to seperate it into multiple projects