I am a complete newbie that is trying to use gradle to automate a non-Java (e.g. JVM) build. As part of the build I need to make sure that certain files are present. It must fail if these files are not present. I configured it like this:
I figured it out. This question was based on my noob misunderstanding of the system. Here is an example that shows how to do the pre-condition checks I needed.
// Demonstrate how to do simple pre-condition checks for files.
apply plugin: 'base'
// Verify that the pre-conditions for this run
// are met.
task checkPreConditions {
outputs.files files('setup.json', 'README.txt')
doFirst {
def msg = []
outputs.files.getFiles().each { f ->
if (!f.exists()) {
msg += "ERROR: required file does not exist ${f}."
} else {
println "INFO: ${it} okay ${f}"
}
}
if (msg.size()) {
throw new GradleException(msg.join("\n"))
}
}
}
// Use the preCondition files.
task x1(dependsOn: checkPreConditions) {
doLast {
project.checkPreConditions.outputs.getFiles().each { f ->
println "INFO: ${it} found ${f}"
}
}
}