Issue - creating directory with gradle doesn't work

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 loading the shell with, gradle wrapper

I ran:

/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

      

Everything seems to be going well. 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 can create a directory in the shell.
  • Enough disk space.

Please advise what I may be doing wrong here with Gradle unable to create a directory, but what does Gradle indicate it was successful? Any troubleshooting tips would be appreciated.

Thank!

+3


source to share


1 answer


Perhaps the copy task didn't do anything, it's "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 it has to do with a copy task that requires inside and out.



Try to create a task without copying 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")
    }
}

      

+8


source







All Articles