我想设置一个“通用”任务,它将为多个平台构建应用程序包(它使用 javafxpackager)。该任务的机制适用于创建所有平台捆绑包,但区别在于任务使用的各种属性。
我原以为我会为每个平台创建单独的更高级别的任务,在其中设置平台特定的属性,然后调用/执行/(此处替换正确的 gradle 术语)通用任务。例如。,
task buildMacBundle(dependsOn: ['macBundleConfig', 'buildAppBundle']) << {
// set Mac-specific properties (project.ext properties?)
// call/invoke/execute or whatever the mechanism is called, buildAppBundle task
buildAppBundle.mustRunAfter macBundleConfig
println "building a Mac app bundle"
}
task macBundleConfig << {
println "executing macBundleConfig"
ext {
nativeType = "dmg"
bundleAppName = 'My App'
}
delete ("${buildDir.name}/dist/${bundleAppName}.dmg")
}
task buildWindowsBundle << {
// omitted for brevity, but just like buildMacBundle except for property values
}
task buildAppBundle << {
println "nativeType: ${project.ext.nativeType}" // it stumbles here!
def cmd = [
"${javapackager}",
"-deploy",
"-native", "${project.ext.nativeType}",
"-name",
"${project.bundleAppName}",
"-outdir",
"${buildDir.name}${File.separator}dist",
"-outfile",
"MyApp",
"-srcdir",
"${buildDir.name}${File.separator}${libsDir.name}",
"-appclass",
"org.pf.app.MyApp"
]
println cmd.join(" ")
def javapackager = exec {
workingDir "${project.projectDir.absolutePath}"
commandLine cmd
}
}
但是当我运行“buildMacBundle”时,我得到
* What went wrong:
Execution failed for task ':buildAppBundle'.
> cannot get property 'nativeType' on extra properties extension as it does not exist
如何定义特定任务中的属性,然后调用通用任务?