Is it possible to ignore specific error codes from a JavaExec task?

I’m currently running a gradle bootRun task under IntelliJ Idea. When I run the bootRun task, my application starts correctly, and I can interact with it with no issues. When I try to kill the running gradle task from IntelliJ, it exits with an error code of 143 (which I’m led to believe is the correct error code since the IntelliJ container is SIGKILLing the bootRun task). What I’m trying to get is something that allows me to ignore the 143 exit code (since it’s not really an error), while passing out any other non-zero exit codes as errors. I tried using the ignoreExitValue () on the bootRun task and that shows that the task was cancelled (which is a slightly better outcome, but still not perfect). Is there any way I can get the JavaExec task to treat a single non-zero status (143) as a non-error?

Use the flag you found and add a doLast { ... } action that gets the executionResult from the task and calls assertNormalExitValue on it if exitValue is not 143.

The executionResult stuff appears to be unavailable in the version of Gradle that we’re currently using (5.4.1). Hopefully, I’ll be able to use this once we migrate our build to a more recent version of Gradle. Thanks for the help.

Then use execResult. executionResult is just the new Provider based replacement.

So I tried the following:

    doLast {
        if (execResult.exitValue == 143) { // Error occurs on this line...
            println "Success"
        } else {
            println "Fail"
            execResult.assertNormalExitValue ()
        }
    }

When I use that it fails with the following error:

Build file '/home/sdussin/NewIdeaProjects/ndms_data_services_new_2/NDMS_DS_AllServices_SB/build.gradle' line: 187

Execution failed for task ':NDMS_DS_AllServices_SB:bootRun'.
> Could not get unknown property 'execResult' for task ':NDMS_DS_AllServices_SB:bootRun' of type org.springframework.boot.gradle.tasks.run.BootRun.

This is running with Gradle 5,4,1

Ah, sorry, execResult is on AbstractExecTask and thus Exec, but not JavaExec.
For JavaExec which is a superclass of BootRun you indeed have to update from that ancient (04/2019) Gradle version to something beyond 6.1 first. :slight_smile:

Ok. that’s what I was afraid of. I work for an organization that doesn’t like to upgrade infrastructure, but luckily a gradle upgrade to 7.6 is on the horizon. Until then, I’ll just limp along with the error,

Thanks for the help…

1 Like