This issue was happening because the application was run using gradle with the run task defined by the application plugin.
run
application
The issue was fixed when I ran the program (executable jar) directly via the terminal, without using gradle.