这是我的任务:
task less(group:'web',dependsOn:checkDirs) << {
file(skinsDir).listFiles().each { dir ->
if (dir.isDirectory() && dir.list().contains("pmc.less")) {
def inFile = dir.toPath().resolve("pmc.less").toString()
def outFile = "$buildDir/css/skins/${dir.name}/pmc.css"
def minOutFile = "$buildDir/css/skins/${dir.name}/pmc.min.css"
exec {
workingDir dir
commandLine "lessc",inFile,">",outFile
}
}
}
}
当我跑步时
gradle -i less
然后命令在信息级别输出中正确列出:
:flat_pmc:less
Executing task ':flat_pmc:less' (up-to-date check took 0.0 secs) due to:
Task has not declared any outputs.
Starting process 'command 'lessc''. Working directory: /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/contrast Command: lessc /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/contrast/pmc.less > /home/dys/dev/synosteel/flat_pmc/build/css/skins/contrast/pmc.css
Successfully started process 'command 'lessc''
Starting process 'command 'lessc''. Working directory: /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/eggshell Command: lessc /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/eggshell/pmc.less > /home/dys/dev/synosteel/flat_pmc/build/css/skins/eggshell/pmc.css
Successfully started process 'command 'lessc''
Starting process 'command 'lessc''. Working directory: /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/sand Command: lessc /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/sand/pmc.less > /home/dys/dev/synosteel/flat_pmc/build/css/skins/sand/pmc.css
Successfully started process 'command 'lessc''
Starting process 'command 'lessc''. Working directory: /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/nebel Command: lessc /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/nebel/pmc.less > /home/dys/dev/synosteel/flat_pmc/build/css/skins/nebel/pmc.css
Successfully started process 'command 'lessc''
Starting process 'command 'lessc''. Working directory: /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/aqua Command: lessc /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/aqua/pmc.less > /home/dys/dev/synosteel/flat_pmc/build/css/skins/aqua/pmc.css
Successfully started process 'command 'lessc''
Starting process 'command 'lessc''. Working directory: /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/venezia Command: lessc /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/venezia/pmc.less > /home/dys/dev/synosteel/flat_pmc/build/css/skins/venezia/pmc.css
Successfully started process 'command 'lessc''
Starting process 'command 'lessc''. Working directory: /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/inverno Command: lessc /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/inverno/pmc.less > /home/dys/dev/synosteel/flat_pmc/build/css/skins/inverno/pmc.css
Successfully started process 'command 'lessc''
:flat_pmc:less (Thread[Daemon worker Thread 6,5,main]) completed. Took 1.722 secs.
“正确列出”是指如果我复制lessc /home/dys/dev/synosteel/flat_pmc/src/webapp/m3/skins/venezia/pmc.less > /home/dys/dev/synosteel/flat_pmc/build/css/skins/venezia/pmc.css
直接在控制台中运行它,则会创建css文件。
但是使用gradle执行无法创建css文件。
这里发生了什么?
答案 0 :(得分:0)
commandLine
仅用于传递命令名和参数,它不支持shell重定向语法。试试这个:
exec {
workingDir dir
commandLine "lessc",inFile
standardOutput = new FileOutputStream(outFile)
}