I’ve a built a gradle multi-project environtment. So then, I’ve
infrastructure
---+build.gradle
---+gradle.settings
---+project1
---+build.gradle
---+project2
---+build.gradle
---+project3
---+build.gradle
In infrastructure/build.gradle
I take advantage of this file location in order to add some deploy tasks on each sub-web-project:
class RemoteContainer {
String name
String container
String hostname
Integer port
String username
String password
String purpose
}
def remoteContainers = [new RemoteContainer(
name: 'wildfly8',
container: 'wildfly8x',
hostname: 'localhost',
port: 8888,
username: 'living',
password: 'l5ngdgtl',
purpose: 'development'
),
new RemoteContainer(
name: 'glassfish4',
container: 'glassfish4x',
hostname: '128.199.57.232',
port: 4444,
username: 'admin',
password: 'l5ngdgtl',
purpose: 'development'
)
]
gradle.projectsEvaluated {
configure(webProjects()) {
apply plugin: 'com.bmuschko.cargo'
apply plugin: 'com.bmuschko.cargo-base'
dependencies {
cargo 'org.wildfly:wildfly-controller-client:8.2.0.Final'
cargo 'org.codehaus.cargo:cargo-core-uberjar:1.4.16'
cargo 'org.glassfish.deployment:deployment-client:3.1.1'
cargo 'org.codehaus.cargo:cargo-ant:1.4.16'
}
remoteContainers.each { config ->
task "deployRemote${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoDeployRemote) {
description = "Deploys WAR to remote Web Application Server: '${config.name}'."
containerId = config.container
hostname = config.hostname
port = config.port
username = config.username
password = config.password
dependsOn war
}
task "undeployRemote${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoUndeployRemote) {
description = "Deploys WAR to remote Web Application Server: '${config.name}'."
containerId = config.container
hostname = config.hostname
port = config.port
username = config.username
password = config.password
}
}
}
}
So each web-project is going to be provided with a deployRemote
and a undeployRemote
.
By other hand, on each web-project I’ve create some war
tasks according to its scope. So, I’m able to create a war file for a dev, QA, testing and production environtments:
task createQAWar(type: War, dependsOn: classes) {
archiveName "webapi-demo-${versioning.info.display}.war"
destinationDir = file("$buildDir/dist")
webInf {
from('scopes') {
include 'demo.persistence.xml'
rename('demo.persistence.xml', 'persistence.xml')
into('classes/META-INF/')
}
from('scopes') {
include 'configuration.demo.properties'
rename('configuration.demo.properties', 'scope.properties')
into('classes/')
}
}
}
task createDevelopmentWar(type: War, dependsOn: classes) {
archiveName "webapi-dev-${versioning.info.display}.war"
destinationDir = file("$buildDir/dist")
webInf {
from('scopes') {
include 'development.persistence.xml'
rename('development.persistence.xml', 'persistence.xml')
into('classes/META-INF/')
}
from('scopes') {
include 'configuration.development.properties'
rename('configuration.development.properties', 'scope.properties')
into('classes/')
}
}
}
task createTestingWar(type: War, dependsOn: classes) {
archiveName "webapi-test-${versioning.info.display}.war"
destinationDir = file("$buildDir/dist")
webInf {
from('scopes') {
include 'testing.persistence.xml'
rename('testing.persistence.xml', 'persistence.xml')
into('classes/META-INF/')
}
from('scopes') {
include 'configuration.testing.properties'
rename('configuration.testing.properties', 'scope.properties')
into('classes/')
}
}
}
task createProductionWar(type: War, dependsOn: classes) {
archiveName "webapi-prod-${versioning.info.display}.war"
destinationDir = file("$buildDir/dist")
webInf {
from('scopes') {
include 'production.persistence.xml'
rename('production.persistence.xml', 'persistence.xml')
into('classes/META-INF/')
}
from('scopes') {
include 'configuration.production.properties'
rename('configuration.production.properties', 'scope.properties')
into('classes/')
}
}
}
task createDists(dependsOn: [createQAWar, createDevelopmentWar, createTestingWar, createProductionWar])
So, I don’t quite to understand how I link un/deploy
tasks with each custom-made war
tasks. Some times I would like to deploy qa war file to QA container
or deploy dev war file to DEV container
…
Any ideas?