通常我们使用SAP Hybris ant结构来构建我们的系统。当我们用它构建Dockerimage时,它变得有点复杂,所以我们想用渐变来包装所有这些
ant.importBuild "${ProjectBaseDir}/bin/platform/build.xml"
repositories {
jcenter()
}
task run() {
doLast {
exec {
workingDir "${ProjectBaseDir}/bin/platform"
executable "./hybrisserver.sh"
}
}
}
这是我们要做的第一步。。导入gradle中的ant脚本,这样我们就可以在gradle中获得所有可用的任务。构建docker图像的下一步(就蚂蚁而言(是:
ant production -Dproduction.include.tomcat=false -Dproduction.legacy.mode=false -Dtomcat.legacy.deployment=false -Dproduction.create.zip=false
然后是
ant createPlatformImageStructure
docker build -t platform .
我正在考虑定义一个新任务
task buildImage {
dependsOn 'production'
dependsOn 'createPlatformImageStructure'
doLast {
// do the docker stuff
}
}
但是我如何将参数(ant production -Dproduction.include.tomcat=false -Dproduction.legacy.mode=false -Dtomcat.legacy.deployment=false -Dproduction.create.zip=false
(合并到"生产"?
更新:
Ant属性现在是这样处理的:
task dockerimage (dependsOn : production) {
doFirst {
ant.properties['production.include.tomcat'] = false
ant.properties['production.legacy.mode'] = false
ant.properties['tomcat.legacy.deployment'] = false
ant.properties['production.create.zip'] = false
}
仍然没有运气。当蚂蚁没有运行这些设置时,就会出现
我还必须从Gradle执行平台ant
命令。我构建了一个包装器,而不是导入脚本。它很好用,所以我希望它对你有用。包装器是跨平台的。
文件:
scripts/ant.sh
-在Unix/Linux上执行平台ant
二进制文件
#!/usr/bin/env sh
(
. ./setantenv.sh
echo ''
echo Executing: ant $@
echo ''
ant $@
)
scripts/ant.bat
-在Windows上执行平台ant
二进制文件
@echo off
setlocal
call setantenv.bat
echo:
echo Executing: ant %*
echo:
ant %*
endlocal
gradle/platformScript.gradle
-执行平台脚本(我只实现了ant
,但您可以添加更多(
import org.gradle.internal.os.OperatingSystem
void platformScript(def parameters) {
def script = parameters['script'] ?: 'ant'
def arguments = parameters['arguments']
if (!(arguments instanceof Collection)) {
arguments = [arguments]
}
def args = []
def extension
if (OperatingSystem.current().isWindows()) {
args << 'cmd'
args << '/c'
extension = 'bat'
} else {
extension = 'sh'
}
def scriptFile = "${rootProject.rootDir}/scripts/${script}.${extension}"
if (!scriptFile.exists()) {
throw new IllegalArgumentException("Script "${script}" does not exist! Full path: ${scriptFile.absolutePath}")
}
args << scriptFile.absolutePath
if (OperatingSystem.current().isWindows()) {
for (def argument in arguments) {
def index = argument.indexOf('=')
if (index == -1) {
args << argument
} else {
def name = argument.substring(0, index)
def value = argument.substring(index + 1).replace('"', '""')
args << "${name}="${value}""
}
}
} else {
args.addAll(arguments)
}
exec {
workingDir "${ProjectBaseDir}/bin/platform"
commandLine args
}
}
ext {
platformScript = this.&platformScript
}
示例build.gradle
:
apply from: "${rootProject.rootDir}/gradle/platformScript.gradle"
task cleanPlatform() {
doFirst {
// executes: ant clean
platformScript arguments: 'clean'
}
}
tasks.clean.dependsOn('cleanPlatform')
task production() {
doFirst {
// executes: ant production -Dproduction.include.tomcat=false ...
platformScript arguments: [
'production',
'-Dproduction.include.tomcat=false',
'-Dproduction.legacy.mode=false',
'-Dtomcat.legacy.deployment=false',
'-Dproduction.create.zip=false'
]
}
}
Ant的属性将使用处理
ant.properties['production.include.tomcat'] = false
问题是在hybris蚂蚁结构中。