Have been building & deploying my application as an EAR (JAR & WAR) using Gradle Groovy:
task deleteFiles(type: Delete) {
project.logger.lifecycle(">>>>> 2 deleteFiles")
delete fileTree("./build/libs") {
include "**/NOTiFYmoto*.?ar"
}
delete fileTree("./src/main/application") {
include "**/NOTiFYmoto*.war"
include "**/NOTiFYmoto*.jar"
include "**/NOTiFYmoto*.ear"
}
}
task NOTiFYmotoWAR(type: War) {
project.logger.lifecycle(">>>>> 3 NOTiFYmotoWAR")
dependsOn deleteFiles
archiveFileName = "NOTiFYmotoWAR.war"
rootSpec.exclude("**/dto/*")
rootSpec.exclude("**/ean/*")
rootSpec.exclude("**/ejb/*")
rootSpec.exclude("**/entity/*")
rootSpec.exclude("**/filter/*")
rootSpec.exclude("**/gson/*")
rootSpec.exclude("**/showwcase/*")
rootSpec.exclude("**/morphia-*.jar")
rootSpec.exclude("**/mongo*.jar")
rootSpec.exclude("**/bson*.jar")
rootSpec.exclude("**/surefire*.jar")
rootSpec.exclude("**/primefaces/**")
rootSpec.exclude("**/controller/**")
rootSpec.exclude("**/webservices/*")
rootSpec.exclude("**/checkstyle*.jar")
rootSpec.exclude("**/classgraph*.jar")
rootSpec.exclude("**/kotlin*.jar")
rootSpec.exclude("**/NOTiFYmoto*.jar")
rootSpec.exclude("**/NOTiFYmoto*.war")
}
task NOTiFYmotoJAR(type: Jar) {
project.logger.lifecycle(">>>>> 4 NOTiFYmotoJAR")
dependsOn NOTiFYmotoWAR
archiveFileName = "NOTiFYmotoJAR.jar"
from("./src/main/java") {
include "META-INF/**"
}
// Exclude
rootSpec.exclude("**/jsf/SliderViewBean.class")
rootSpec.exclude("**/push/PushBean.class")
from("./build/classes/java/main") {
include "*/**"
}
// Kotlin
from("./build/classes/kotlin/main") {
include "*/**"
}
}
task copyNOTiFYmotoWAR(type: Copy) {
project.logger.lifecycle(">>>>> 5 copyNOTiFYmotoWAR")
dependsOn NOTiFYmotoJAR
from file("./build/libs/NOTiFYmotoWAR.war")
into file("./src/main/application")
}
task copyNOTiFYmotoJAR(type: Copy) {
project.logger.lifecycle(">>>>> 6 copyNOTiFYmotoJAR")
dependsOn copyNOTiFYmotoWAR
from file("./build/libs/NOTiFYmotoJAR.jar")
into file("./src/main/application")
}
task NOTiFYmotoEAR(type: Ear) {
project.logger.lifecycle(">>>>> 7 NOTiFYmotoEAR")
apply plugin: "ear"
dependsOn copyNOTiFYmotoJAR
archiveFileName = "NOTiFYmoto.ear"
manifest {
from("./src/main/resources/META-INF/MANIFEST.MF")
}
exclude "**/*.class"
exclude "**/asm-Java.jar"
exclude "**/jboss-deployment-structure.xml"
dependencies {
earlib group: "com.google.code.gson", name: "gson", version: "2.10", ext: "jar"
earlib group: "org.apache.httpcomponents", name: "httpclient", version: "4.5.13", ext: "jar"
earlib group: "org.apache.httpcomponents", name: "httpcore", version: "4.4.14", ext: "jar"
earlib group: "org.jetbrains.kotlin", name: "kotlin-stdlib", version: "1.8.21", ext: "jar"
earlib group: "dev.morphia.morphia", name: "morphia-core", version: "2.3.0", ext: "jar"
earlib group: "org.mongodb", name: "mongodb-driver-core", version: "4.9.1", ext: "jar"
earlib group: "org.mongodb", name: "mongodb-driver-sync", version: "4.9.1", ext: "jar"
earlib group: "org.mongodb", name: "bson", version: "4.9.1", ext: "jar"
earlib group: "net.bytebuddy", name: "byte-buddy", version: "1.14.4", ext: "jar"
earlib group: "io.github.classgraph", name: "classgraph", version: "4.8.157"
}
}
My WAR, JAR builds as an EAR & deploys on WildFly 28.x & runs.
NOTiFYmoto.ear
NOTiFYmoto.jar
NOTiFYmoto.wa
I’ve migrate to Gradle Kotlin DSL. It’s now unable to create the complete EAR (JAR & WAR):
tasks.create<Delete>("deleteFiles") {
project.logger.lifecycle(">>>>> 2 deleteFiles")
delete {
fileTree("./build/libs")
file("**/NOTiFYmoto*.?ar")
}
delete {
fileTree("./src/main/application")
files("**/NOTiFYmoto*.war")
files("**/NOTiFYmoto*.jar")
files("**/NOTiFYmoto*.ear")
}
}
tasks.register<War>("NOTiFYmotoWAR") {
project.logger.lifecycle(">>>>> 3 NOTiFYmotoWAR")
dependsOn("deleteFiles")
archiveFileName.set("NOTiFYmotoWAR.war")
rootSpec.exclude("**/dto/*")
rootSpec.exclude("**/ean/*")
rootSpec.exclude("**/ejb/*")
rootSpec.exclude("**/entity/*")
rootSpec.exclude("**/filter/*")
rootSpec.exclude("**/gson/*")
rootSpec.exclude("**/showwcase/*")
rootSpec.exclude("**/morphia-*.jar")
rootSpec.exclude("**/mongo*.jar")
rootSpec.exclude("**/bson*.jar")
rootSpec.exclude("**/surefire*.jar")
rootSpec.exclude("**/*primefaces*/**")
rootSpec.exclude("**/controller/**")
rootSpec.exclude("**/webservices/*")
rootSpec.exclude("**/checkstyle*.jar")
rootSpec.exclude("**/classgraph*.jar")
rootSpec.exclude("**/kotlin*.jar")
rootSpec.exclude("**/NOTiFYmoto*.jar")
rootSpec.exclude("**/NOTiFYmoto*.war")
}
tasks.register<Jar>("NOTiFYmotoJAR") {
project.logger.lifecycle(">>>>> 4 NOTiFYmotoJAR")
dependsOn("NOTiFYmotoWAR")
archiveFileName.set("NOTiFYmotoJAR.jar")
from("./src/main/java") {
//"META-INF/**"
fileTree("META-INF/**")
}
// Exclude
rootSpec.exclude("**/jsf/SliderViewBean.class")
rootSpec.exclude("**/push/PushBean.class")
from("./build/classes/java/main") {
//include "*/**"
fileTree("*/**")
}
// Kotlin
from("./build/classes/kotlin/main") {
//include "*/**"
fileTree("*/**")
}
}
tasks.register<War>("copyNOTiFYmotoWAR") {
project.logger.lifecycle(">>>>> 5 copyNOTiFYmotoWAR")
dependsOn("NOTiFYmotoJAR")
from(File(buildDir, "./build/libs/NOTiFYmotoWAR.war"))
into(File(buildDir, "./src/main/application"))
}
tasks.register<Jar>("copyNOTiFYmotoJAR") {
project.logger.lifecycle(">>>>> 6 copyNOTiFYmotoJAR")
dependsOn("copyNOTiFYmotoWAR")
from(File(buildDir, "./build/libs/NOTiFYmotoJAR.jar"))
into(File(buildDir, "./src/main/application"))
}
tasks.register<Ear>("NOTiFYmotoEAR") {
project.logger.lifecycle(">>>>> 7 NOTiFYmotoEAR")
apply(plugin = "ear")
dependsOn("copyNOTiFYmotoJAR")
archiveFileName.set("NOTiFYmoto.ear")
manifest {
from("./src/main/resources/META-INF/MANIFEST.MF")
}
exclude("**/*.class")
exclude("**/asm-Java.jar")
exclude("**/jboss-deployment-structure.xml")
dependencies {
earlib(group = "gson", name = "gson", version = "2.10", ext = "jar")
earlib(group = "gson", name = "gson", version = "2.10", ext = "jar")
earlib(group = "httpcomponents", name = "httpclient", version = "4.5.14", ext = "jar")
earlib(group = "httpcomponents", name = "httpcore", version = "4.4.16", ext = "jar")
earlib(group = "kotlin", name = "kotlin-stdlib", version = "1.8.10", ext = "jar")
earlib(group = "morphia", name = "morphia-core", version = "2.3.0", ext = "jar")
earlib(group = "mongodb", name = "mongodb-driver-core", version = "4.9.1", ext = "jar")
earlib(group = "mongodb", name = "mongodb-driver-sync", version = "4.9.1", ext = "jar")
earlib(group = "mongodb", name = "bson", version = "4.9.1", ext = "jar")
earlib(group = "classgraph", name = "classgraph", version = "4.8.158", ext = "jar")
}
}
I always creates:
NOTiFYmoto.ear
NOTiFYmoto.jar
NOTiFYmoto.war
NOTiFYmotoJAR.jar
NOTiFYmotoWAR.war
The EAR won’t deploy the combined ‘NOTiFYmotoJAR.jar & NOTiFYmotoWAR.war’ with:
./gradlew build clean
>>>>> 2 deleteFiles
>>>>> 3 NOTiFYmotoWAR
>>>>> 4 NOTiFYmotoJAR
>>>>> 5 copyNOTiFYmotoWAR
>>>>> 6 copyNOTiFYmotoJAR
>>>>> 7 NOTiFYmotoEAR
./gradlew NOTiFYmotoEAR
>>>>> 2 deleteFiles
>>>>> 7 NOTiFYmotoEAR
>>>>> 6 copyNOTiFYmotoJAR
>>>>> 5 copyNOTiFYmotoWAR
>>>>> 4 NOTiFYmotoJAR
>>>>> 3 NOTiFYmotoWAR
Gives:
Ear File - 6.1 MB
Java JAR file - 2 KB
War File - 311.6 MB
Java JAR file - 111 KB
War File - 220.2 MB
Won’t combine an EAR of ‘Java JAR’ & ‘Java JAR file’?
task NOTiFYmotoEAR(type: Ear) {