From 28b43326f826ddfc43ee27e8c8dadaf15d906479 Mon Sep 17 00:00:00 2001 From: James Ward Date: Tue, 19 Jul 2016 15:42:38 -0600 Subject: [PATCH] proper task lifecycle --- build.gradle | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index e2c06270..b8a723c8 100644 --- a/build.gradle +++ b/build.gradle @@ -144,13 +144,7 @@ subprojects { String basePath = it.absolutePath.replaceAll('\\.java', '') File outFile = new File(basePath + '.out') - if(outFile.exists()) - outFile.delete() - if(tags.outputLine) - outFile << tags.outputLine + "\n" File errFile = new File(basePath + '.err') - OutputStream runStandardOutput = new TeeOutputStream(new FileOutputStream(outFile, true), System.out) - OutputStream runErrorOutput = new TeeOutputStream(new FileOutputStream(errFile), System.err) task "$tags.fileRoot"(type: JavaExec, dependsOn: tags.runFirst) { main = tags.mainClass @@ -158,13 +152,21 @@ subprojects { args = tags.args jvmArgs = tags.jVMArgs ignoreExitValue = tags.validateByHand || tags.throwsException - standardOutput = runStandardOutput - errorOutput = runErrorOutput - } << { - println "$outFile size():> " + outFile.size() - println "$errFile size():> " + errFile.size() - if (outFile.size() == 0) outFile.delete() - if (errFile.size() == 0) errFile.delete() + doFirst { + if(outFile.exists()) + outFile.delete() + if(tags.outputLine) + outFile << tags.outputLine + "\n" + + standardOutput = new TeeOutputStream(new FileOutputStream(outFile, true), System.out) + errorOutput = new TeeOutputStream(new FileOutputStream(errFile), System.err) + } + doLast { + println "$outFile size():> " + outFile.size() + println "$errFile size():> " + errFile.size() + if (outFile.size() == 0) outFile.delete() + if (errFile.size() == 0) errFile.delete() + } } } // exclude java sources that will not compile