I 've a multi-project gradle configuration. So I’ve got a build.gradle
for each subproject and another one where I define general tasks.
Basicly, in the general build.gradle
file I set out performing environtments, each one for production
, pre-production
, development
, and so on purposes.
I set several containers defining a class:
class RemoteContainer {
String name
String container
String hostname
Integer port
String username
String password
String purpose
}
So, I set the purpose of the container setting purpose
field to 'production'
, 'pre-production'
or 'development'
.
Then, I’m able to create several containers:
def developmentRemoteContainers = [
new RemoteContainer(
name: 'wildfly8',
container: 'wildfly8x',
hostname: '----',
port: ----,
username: '----',
password: '----'
purpose: 'development'
),
new RemoteContainer(
name: 'glassfish4',
container: 'glassfish4x',
hostname: '----',
port: ----,
username: '----',
password: '----'
purpose: 'development'
)
]
def preproductionRemoteContainers = [
new RemoteContainer(
name: 'wildfly8',
container: 'wildfly8x',
hostname: '----',
port: ----,
username: '----',
password: '----'
purpose: 'pro-production'
),
new RemoteContainer(
name: 'glassfish4',
container: 'glassfish4x',
hostname: '----',
port: ----,
username: '----',
password: '----'
purpose: 'pre-production'
)
]
def productionUserRemoteContainers = [
new RemoteContainer(
name: 'wildfly8',
container: 'wildfly8x',
hostname: '---',
port: ----,
username: '----',
password: '----'
purpose: 'production'
),
new RemoteContainer(
name: 'glassfish4',
container: 'glassfish4x',
hostname: '----',
port: ----,
username: '----',
password: '----'
purpose: 'production'
)
]
After that, I create tasks according the content of each remote container:
Example tasks:
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, it’s the way how I’m creating my deploy and undeploy tasks for each container and performing context.
As you’re able to figure out each task depends of the war task. So, my projects have a file containing a string like ${stringKey}
which I need to replace it according of each container purpose.
So, ${stringKey}
must be replaced by config.purpose
.
I’ve absolutly no idea how to do that.
Any ideas?