how to ensure subprojects*.copy (used to copy xml test report files to root project buildDir) always run even there are test failures, and if with ignoreFailures set to true how to ensure the build is failed? ‘–continue’ does not solve the problem.
add my code in root project build.gradle
subprojects {
apply plugin: ‘java’
test.ignoreFailures = true
test.doLast{
copy {
from ‘build/test-results’
into ‘…/build/xml-report’
include ‘**/*.xml’
}
} }
issue is resolved as below:
subprojects {
apply plugin: ‘java’
task copyReport {
copy {
from ‘build/test-results’
into ‘…/build/xml-report’
include ‘**/*.xml’
}
} }
task testReport {
subprojects*.copyReport }
and then run “gradle clean build testReport --continue”
This solution has several problems. In particular, a task should never call another task. A better approach is to use a finalizer task. Something like:
subprojects {
apply plugin: "java"
task copyReport(type: Copy) {
from "build/test-results"
into "$rootDir/build/xml-report"
}
test.finalizedBy(copyReport)
}
PS: Please always wrap code snippets in HTML code blocks.
1 Like