DEV Community

Akop Akopov
Akop Akopov

Posted on

How to Run and Debug Groovy code in VSCode

Hi, all. This is my first article here, so please don't be strict.

For a log time I used Pycharm of Jetbrains. It is really cool software. But not for a long time I became curious, why so many people use vscode and I started to make my all experiments:
I have configured my vscode for Python and several other languages.

But in my current job I need to program on Groovy programming language. *Spolier, Intelij Idea works with Groovy out of the box, but if you curious like me, this article might be interesting to you.

I have spent some time, in attempt to configure my VScode with a help of Github copilot - no luck. So when I was tired, and I was ready to give up, i decided to try Google Gemini. And It showed me different answer. So next morning I decided to try solution of Google Gemini.
After several attempts I succeed. I'm Linux user, so my guide will be for Linux users

Here is my guide:

  • Open "Run And Debug" tab.
  • Click on "create launch.json file"
  • Select Java from dropdown list
  • Replace content of the launch.json file with content below:
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug Standalone Groovy Script",
            "request": "launch",
            "cwd": "${workspaceFolder}",
            "args": [
                "${file}"
            ],
            "classPaths": [
                //Put here list of Groovy jars as a list of strings
            ],
            "mainClass": "groovy.ui.GroovyMain",
            "console": "integratedTerminal"

        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

if you have used sdkman installator, your groovy jars will be:

/home/YOUR_USER/.sdkman/candidates/groovy/VERSION/

if you have class with main method, replace "mainClass" value with a path to your class.

Here is bash script which prints all of the paths of groovy jar files as a list of separated strings

groovy_lib_path="/home/YOUR_USER/.sdkman/candidates/groovy/4.0.28/lib"
find "$groovy_lib_path" -maxdepth 1 -name "*.jar" | sed 's|^|                "|; s|$|",|'
Enter fullscreen mode Exit fullscreen mode
  • Save launch.json file
  • press F5

Top comments (0)