我有一個多項目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