Developer's Diary
Software development, with Terry Ebdon
11-Jun-2020 Grails reliability

Fighting demons

I've been using Gradle for at least 18 months, with no great problem. It's a nice app. It seems to get quite confused when running Grails though. I often find that zapping the Gradle JVM, and allowing it to be recreated, solves weird start up failures with the grailsw run-app command. I'm reluctant to disable the Gradle daemon as it's a brute force approach that applies to all projects, and it's only been a problem with my prototype Grails app. I suspect I will need to disable the daemon. For the moment I'm killing the thing, as needed, via a script.

Hunting the demon

The Java jps command lists the Java instances, giving the name and process ID.

C:\projects\prototype>jps
13140 GradleDaemon
13492 GroovyStarter
5668 Jps
C:\projects\prototype>

I need to kill the correct process. A perfect task for my favourite mini-language, awk.

$2 == "GradleDaemon" {
print "TaskKill /F /PID " $1 " /T" > "KillDaemonTemp.cmd"
}

Notice that I'm writing the kill command to a file, and not executing it from awk. I was getting odd behaviour with gawk and it wasn't worth the effort of debugging for a quick script. The script reads the output of jps and generates a kill file. The whole thing is wrapped in a command script:

jps | awk -f KillDaemon.awk && KillDaemonTemp.cmd && del KillDaemonTemp.cmd

10-JUN-2020 👈 Top of page 👉 12-JUN-2020

© 2020 Terry Ebdon.

Find me coding on GitHub, networking on LinkedIn, answering questions on Stack Exchange and hanging out on twitter.