我有来自gradle-js-插件的这些任务
combineJs {
source = sourceJs
dest = file(destDirJs + "/all.js")
}
minifyJs {
source = combineJs
dest = file( destDirJs + "/all-min.js")
closure {
warningLevel = 'QUIET'
}
}
gzipJs {
source = minifyJs
dest = file(destDirJs + "/all-gzip-min.js")
}我的问题是,我将不得不更改sourceJs的值,并多次设置times。所以我不想有太多的重复代码。
所以我试着做这样的事情:
task gzipAll {
sourceJs = ["WebContent/plugin/bootstrap-modal/js/bootstrap-modalmanager.js", "WebContent/plugin/bootstrap-modal/js/bootstrap-modal.js", "WebContent/js/bootstrap-dropdown.js", "WebContent/js/mandatory/bootstrap-analytics-setup.js"]
destDirJs = "WebContent/js/mandatory"
tasks.combineJs().execute;
tasks.minifyJs().execute;
tasks.gzipJs().execute;
//Here I need to change sourceJs and destDir and call all the task again.
}事实上,我在黑暗中做了一个很长的尝试,我得到了一个例外:
Caused by: groovy.lang.MissingPropertyException: Could not find property 'sourceJs' on task ':combineJs'.我也尝试过这样的方法,但没有起作用。有一些例外:
combineJs(sourceJs, destDirJs) {
source = $sourceJs
dest = file($destDirJs + "/all.js")
}有更多经验的人能帮我解决这个问题吗?很简单,对吧?谢谢。
发布于 2014-03-25 18:05:55
我还没有测试它,但是因为gradle脚本是groovy脚本,所以您应该能够这样做。
['dir1', 'dir2'].eachWithIndex { dir, index ->
task "combineJs_$index"(type: combineJs) {
source = dir
dest = file(destDirJs + "/$index.js")
}
task "minifyJs_$index" (type: minifyJs) {
source = "combineJs_$index"
dest = file( destDirJs + "/$index-min.js")
closure {
warningLevel = 'QUIET'
}
}
task "gzipJs_$index" (type: gzipJs) {
source = "minifyJs_$index"
dest = file(destDirJs + "/$index-gzip-min.js")
}
}当然,您需要正确的TaskTypes,并且您可能需要更改输入,但是这应该会让您开始工作。
https://stackoverflow.com/questions/22641195
复制相似问题