def classesDir = file('build/classes') classesDir.mkdirs() task clean(type: Delete) { delete 'build' } task compile { dependsOn 'clean' doLast { if (!classesDir.isDirectory()) { println 'The class directory does not exist. I can not operate' // do something } // do something } }
1 2
> gradle -q compile The class directory does not exist. I can not operate