我有以下build.gradle
:
task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}
apply plugin: 'java'
task filter(type: Copy) {
def subdir = new File(project.buildDir, "subdir")
println("subdir: "+subdir)
if( !subdir.exists() ) {
println("creating subdir")
if(subdir.mkdirs()) {
println("succeeded in making folder")
if(subdir.exists()) {
println("folder exists")
} else {
println("folder does not exist")
}
} else {
println("failed to make folder")
}
} else {
println("folder exists already")
}
}
使用gradle wrapper
下载包装后,我运行:
/tmp/test $ ./gradlew clean filter
subdir: /tmp/test/build/subdir
creating subdir
succeeded in making folder
folder exists
:clean
:filter UP-TO-DATE
BUILD SUCCESSFUL
Total time: 4.121 secs
这似乎表明一切顺利。但是,当我仔细检查时,我得到了这个:
/tmp/test $ ls -l /tmp/test/build/subdir
ls: /tmp/test/build/subdir: No such file or directory
备注:
请告诉Gradle我在这里做错了什么不能创建目录,但是Gradle表示它成功了?任何疑难解答提示将不胜感激。
谢谢!
答案 0 :(得分:8)
可能是复制任务没有做任何事情,是“UP-TO-DATE”。
13:21:40.045 [INFO] [org.gradle.api.internal.tasks.execution.SkipEmptySourceFile
sTaskExecuter] Skipping task ':filter' as it has no source files.
我认为这是由于复制任务需要一个来自和进入。
尝试创建非复制任务,例如
task filter() << {
def subdir = new File(project.buildDir, "subdir")
println("subdir: "+subdir)
if( !subdir.exists() ) {
println("creating subdir")
if(subdir.mkdirs()) {
println("succeeded in making folder")
if(subdir.exists()) {
println("folder exists")
} else {
println("folder does not exist")
}
} else {
println("failed to make folder")
}
} else {
println("folder exists already")
}
}