I want to add an extra task to Gradle "build", specifically to copy a file to resources.
So I do this:
task copySettingsGradle(type: Copy) {
from file("settings.gradle")
into file("src/main/resources")
}
build.dependsOn copySettingsGradle
But if settings.gradle is not there it currently seems to fail silently: the build proceeds as normal.
I want to prevent the build from happening if this required task fails. For that, it seems to me that I need two things: a means of determining that from.file(...)
couldn't find the file, and then a way of setting "failed" flag on the task... or something.
Trying to work this one out led me to AbstractCopyTask
and then CopySourceSpec.from... but I'm none the wiser.
Of course I could use non-DSL Groovy to copy and perform checks of success. But it's the question of marking the required task as failed which puzzles me.
There's a question here, from 8 years ago, about "way to stop a Gradle build". In his answer, Peter Niederwieser says "there have been discussions to add [a way of stopping]".
Furthermore, on this page of the official Gradle documentation, I see that the following expression is used: "The task will be marked as failed" (if a timer runs out). "Marked as failed"... and that means???
I find it pretty amazing that I haven't been able to find any info on this! The concept of "dependency" involves being dependent on the existence or success of something else. Not only can I not find out whether such a mechanism (other than throwing a GradleException
) has now been introduced into Gradle, I can't even find any talk about it. Baffled!