Reputation: 19798
I'd like to be able to run all tests and, if no tests have failed, publish. AFAICT from the task dependency graph, gradlew --continue test publish
will publish even if some tests fail. Is ignoreFailure = true
the right thing to use?
Edit: The project is a multi-module project. I would like all the tests in the project to run and, if any of them fail, the build shouldn't continue to publish.
Upvotes: 2
Views: 2460
Reputation: 3417
With --continue
Gradle will continue to execute all tasks for which the task dependencies have been executed successfully. It will, however, not execute tasks for which dependencies have failed and the overall build will fail if any task has failed during the build.
This can be used to continue the build after tests have failed, but prevent anything from being published to a Maven repository. However, it is insufficient to only set the corresponding dependencies for the publish task, because an artificial task is generated for every publication target. All those tasks need to have their dependencies set correctly so that they are only executed if no tests have failed. This can be achieved for a multi-project build as in the following example which shows some possible dependencies which must run before anything is published:
publish {
// 'javaProjects' is a set of all Java projects, you may want to use 'allprojects' here
dependsOn javaProjects.collect { jp -> jp.tasks.build }
// 'tagVersion' is a task which creates and pushes Git tags in _all_ projects
dependsOn rootProject.tasks.tagVersion
// The following line may not be needed for other projects
dependsOn rootProject.tasks.sonarRunner
}
// now, the same dependencies are set for the created publication tasks
afterEvaluate {
tasks.withType(PublishToMavenRepository).all { publishTask ->
publishTask.dependsOn javaProjects.collect { jp -> jp.tasks.build }
publishTask.dependsOn rootProject.tasks.tagVersion
publishTask.dependsOn rootProject.tasks.sonarRunner
}
}
Upvotes: 0
Reputation: 691983
The --continue
option is precisely used to prevent the build to fail if a test error occurs. Just drop this option. By default, the build will fail (and stop) if a test doesn't pass.
By default, Gradle will abort execution and fail the build as soon as any task fails. This allows the build to complete sooner, but hides other failures that would have occurred. In order to discover as many failures as possible in a single build execution, you can use the --continue option.
Upvotes: 1