我有一个多项目gradle配置。所以我对每个子项目都有一个build.gradle
,另一个是我定义一般任务的地方。
基本上,在一般build.gradle
文件我设置了执行environtments,分别为production
,pre-production
,development
等目的。
我设置几个容器定义一个类:
class RemoteContainer {
String name
String container
String hostname
Integer port
String username
String password
String purpose
}
所以,我设置的容器purpose
字段设置为'production'
,'pre-production'
或'development'
的目的。
然后,我能够创建多个容器:
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'
)
]
之后,创建根据每个远程容器的内容物任务:
实施例的任务:
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
}
}
所以,这就是我为每个容器创建部署和取消部署任务以及执行上下文的方式。
正如你能够找出每个任务取决于战争任务。所以,我的项目有一个文件,其中包含一个像${stringKey}
这样的字符串,我需要根据每个容器目的来替换它。因此${stringKey}
必须被config.purpose
所替换。
编辑
有basicly两个文件:
在
/src/main/resources/META-INF/persistence.xml
:此文件包含数据库服务器的位置信息。根据服务器environtment,数据库的位置是在IP /端口/数据库...例如:<property name="hibernate.ogm.datastore.host" value="${ip}"/> <property name="hibernate.ogm.datastore.port" value="${port}"/>
在
/src/main/resources/configuration.settings.environtment
:该文件只包含此行scope = ${scope}
。
更换必须在war
世代。
我绝对不知道该怎么做。 任何想法?
你在问什么不是很清楚。你想打开一个文件并替换它中的一个字符串?为什么?什么是文件名?生命周期的哪个阶段必须发生?你如何将你的一般build.gradle添加到你的个人项目build.gradle文件? – RaGe
我编辑了这个问题回答了你的问题。 – Jordi