I have the following 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")
}
}
After downloading the wrapper using gradle wrapper I then run:
/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
Which seems to indicate everything went okay. However, when I double check I get this:
/tmp/test $ ls -l /tmp/test/build/subdir
ls: /tmp/test/build/subdir: No such file or directory
Notes:
Please advise what I might be doing wrong here with Gradle that fails to create the directory, but that Gradle indicates it was successful? Any troubleshooting tips would be appreciated.
Thanks!
Might be the copy task has done nothing, is "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.
I think this is due to a Copy task requires a from and into.
Try creating a non copy task like,
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")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With