Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

issue - creating a directory with gradle not working

Tags:

java

shell

gradle

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:

  • This is on MacOS Mavericks.
  • The executing user is able to create the directory at the shell.
  • There is sufficient disk space.

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!

like image 789
Edward Q. Bridges Avatar asked Oct 26 '25 09:10

Edward Q. Bridges


1 Answers

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")
    }
}
like image 115
Mike Rocke Avatar answered Oct 28 '25 22:10

Mike Rocke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!