How can I setup an exec task to “tee” to a file? I want to exec a maven build step and then parse the log. I’d like to use a tee to file approach so the build system shows constant updates and then I can parse to produce a nicer summary that I’d normally get from maven.
Would I add another logger to do this?
def configureExec = { task, executable, workingDir, cmdLine ->
task.executable executable
task.workingDir workingDir
task.args cmdLine.split().toList()
}
task mavenbuild(type:Exec) { task -> configureExec(
task,
getMvnCommand(),
file("${getBuildRootPath()}"),
"--batch-mode -U -Pdist -DskipTests -Dskipinstaller=true
clean install")
}
Thanks
Peter
As can be seen in the Gradle Build Language Reference, there is a Exec.standardOutput property that can be set to any ‘OutputStream’. Gradle doesn’t provide a ‘TeeOutputStream’, but you can, for example, use ‘org.apache.tools.ant.util.TeeOutputStream’, which is available on the build script class path.
Thanks Peter. We just implemented this and it works well
We followed Peter Niederwieser’s suggestion and used the TeeOutput shown below:
project.ext.logFile = new File(logFileName)
project.ext.logFileStream = new FileOutputStream(project.ext.logFile)
project.ext.teeStream = new org.apache.tools.ant.util.TeeOutputStream(task.standardOutput, project.ext.logFileStream)
logging.captureStandardOutput LogLevel.INFO
task.doFirst {
println 'A task message which is logged at INFO level'
}
task.standardOutput project.ext.teeStream
...