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
我该如何定义特定任务中的属性,以便调用通用任务?