Skip to content

Commit 28b4332

Browse files
committed
proper task lifecycle
1 parent 4f8d295 commit 28b4332

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

build.gradle

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,27 +144,29 @@ subprojects {
144144

145145
String basePath = it.absolutePath.replaceAll('\\.java', '')
146146
File outFile = new File(basePath + '.out')
147-
if(outFile.exists())
148-
outFile.delete()
149-
if(tags.outputLine)
150-
outFile << tags.outputLine + "\n"
151147
File errFile = new File(basePath + '.err')
152-
OutputStream runStandardOutput = new TeeOutputStream(new FileOutputStream(outFile, true), System.out)
153-
OutputStream runErrorOutput = new TeeOutputStream(new FileOutputStream(errFile), System.err)
154148

155149
task "$tags.fileRoot"(type: JavaExec, dependsOn: tags.runFirst) {
156150
main = tags.mainClass
157151
classpath = sourceSets.main.runtimeClasspath
158152
args = tags.args
159153
jvmArgs = tags.jVMArgs
160154
ignoreExitValue = tags.validateByHand || tags.throwsException
161-
standardOutput = runStandardOutput
162-
errorOutput = runErrorOutput
163-
} << {
164-
println "$outFile size():> " + outFile.size()
165-
println "$errFile size():> " + errFile.size()
166-
if (outFile.size() == 0) outFile.delete()
167-
if (errFile.size() == 0) errFile.delete()
155+
doFirst {
156+
if(outFile.exists())
157+
outFile.delete()
158+
if(tags.outputLine)
159+
outFile << tags.outputLine + "\n"
160+
161+
standardOutput = new TeeOutputStream(new FileOutputStream(outFile, true), System.out)
162+
errorOutput = new TeeOutputStream(new FileOutputStream(errFile), System.err)
163+
}
164+
doLast {
165+
println "$outFile size():> " + outFile.size()
166+
println "$errFile size():> " + errFile.size()
167+
if (outFile.size() == 0) outFile.delete()
168+
if (errFile.size() == 0) errFile.delete()
169+
}
168170
}
169171
}
170172
// exclude java sources that will not compile

0 commit comments

Comments
 (0)