对不起新手问题,但我还没有看到与在 gradle 项目中将动态任务指定为 defaultTask 相关的示例或问题。
那么,如何将动态 $boostLibName 任务指定为 defaultTasks?
构建.gradle
defaultTasks 'whatgoeshere'
ext {
// The boost directory, which changes according to version
// there should be a better way to do this
boostDir = './boost_1_53_0'
// The list of boost libraries that we want to build
boostLibs = ['smart_ptr', 'filesystem', 'array.hpp']
}
// Create a task to build each boost library
boostLibs.each { def boostLibName ->
println boostLibName
tasks.create(name: boostLibName, dependsOn: aBoostBcp, type: Exec) {
workingDir project.boostDir
def b2compiler = 'toolset=' + System.properties['boost_toolset']
def b2target = '--with-' + boostLibName
def cmd
if(System.properties['platform'] == 'windows') {
//on windows
cmd = ['cmd', '/c', '.\\b2', b2compiler, b2target]
} else {
//on unix and mac
cmd = ['./b2', b2compiler, b2target]
}
// set exec commandLine
//commandLine cmd.split()
commandLine 'cmd', '/c', 'echo', "Command to execute: $cmd"
}
}
背景
我正在尝试在 gradle 中实现跨平台 Boost C++ 构建,您可以在其中引导构建,构建 bcp,使用 bcp 自定义我们的命名空间,最后构建我们依赖的每个 boost 库。