Hoe can I pass through if JavaExec failed?

I have a JavaExec task like this:

tasks.register("run-MyLoader", JavaExec) {
    //jvmArgs = ['-Xmx1g']
    group = ApplicationPlugin.APPLICATION_GROUP
    classpath = sourceSets.main.runtimeClasspath
    mainClass = 'my.run.package.MyLoader'
}

I run this task in a shell script via:

gradle -p /path/to/gradle/project run-MyLoader

Most of the time everything goes fine. (Things get compiled and run and afterwards the shell script can continue working on the results.) So far so good.

Sometimes the running fails with an exception in one of my just compiled Java classes - but afterwards when control comes back to the shell script it still continues .

How can pass through to the shell script the fact that the JavaExec task failed?

That’s a shell script question, not a Gradle question.
Gradle properly quits with a non-0 exit code.
But shell scripts by default to not stop processing in that case.
So you either have to check the exit code manually and handle it or activate that further processing stops in case of error.

1 Like

Of course! Should have realisedof that myself…

Happy gradle-ing! :smile:

1 Like