I have beow tasks in my build.gradle and just wanted to findout whether I can print the app logs while running test task.
The problem with below code is, need to quit from bootRunStartDaemon to go on to next task. So in that case cannot see app logs anymore.
def process;
tasks.register('bootRunStartDaemon') {
doLast {
ProcessBuilder builder = new ProcessBuilder(gradleCommand, "bootRun", "--args='--spring.profiles.active=it'")
builder.redirectErrorStream(true)
builder.directory(projectDir)
process = builder.start()
InputStream stdout = process.getInputStream()
BufferedReader reader = new BufferedReader(new InputStreamReader(stdout))
while ((line = reader.readLine()) != null) {
println line
}
}
}
tasks.register('bootRunStopDaemon') {
doLast {
process.destroy();
process.waitFor();
if (process.isAlive()) {
process.destroyForcibly();
}
}
}
task healthCheck(dependsOn: bootRunStartDaemon) {
// some code
}
tasks.register('integrationTest', Test ) {
description = 'Run integration tests.'
check.dependsOn integrationTest
group = 'verification'
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}
tasks.withType(Test) {
useJUnitPlatform()
// Prints any test outcomes to the console
testLogging {
events "passed", "skipped", "failed"
showStackTraces true
showExceptions true
showCauses true
exceptionFormat "full"
}
}
bootRunStopDaemon.dependsOn(bootRunStartDaemon)
healthCheck.dependsOn(bootRunStartDaemon)
integrationTest.dependsOn(healthCheck)
integrationTest.finalizedBy aggregate, bootRunStopDaemon