Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
JohanCalderon
Discoverer
6,996

Introduction

Sometimes it's necessary to debug code to find a bug — it happened to me too. Back then, our only solution was to use tools like “groovyIDE”, where we could print output to the console, just like old-school PHP developers.

A few months ago, I published a Visual Studio Code extension that provides similar functionality to “groovyIDE” but for a local environment. This local setup also supports external libraries, such as JWT libraries.

The new version of the VS Code extension now allows debugging Groovy scripts locally using JDI (Java Debug Interface). I developed a tool that enables this functionality. Currently, it does not support all Java or Groovy classes.

What do you need?

Installing and Configuring the Extension in VS Code

JohanCalderon_0-1754479103648.png

Before using the extension, you need to configure it properly.

  1. Find Your Java and Groovy Installation Paths

If you've installed Java and Groovy or manually added them to your system PATH, you can find their locations by running the following command in Command Prompt:

JohanCalderon_1-1754479127023.png

JohanCalderon_2-1754479127024.png

This will show you the installation paths for Java and Groovy.

  1. Configure the Extension in VS Code

Open VS Code Settings and search for "Groovy" to configure the extension.

JohanCalderon_3-1754479127025.png

JohanCalderon_4-1754479127027.png

  1. Set Java Path:
    Example:
    C:\programs\jdk1.8.0_441
  2. Set Groovy Path:
    Example:
    C:\programs\groovy-2.4.21

JohanCalderon_5-1754479127028.png

After completing these steps, the VS Code extension will be ready to use for local Groovy script debugging.

Creating a Project

There are three ways to create a project:

Using the wizard – This method creates a folder and an example script.

In VS Code, open the Command Palette, type >cpi, and select SAP CPI: Create a SAP CPI Groovy Script Project.

JohanCalderon_0-1754479359288.png

It will prompt you to select a folder and enter a name for the project.

JohanCalderon_1-1754479384068.png

JohanCalderon_2-1754479384068.png

After providing the folder and project name, a new project is created automatically.

JohanCalderon_0-1754497276787.png

Using SAP CPI Tools Extension – This method creates a project containing the Groovy script code from SAP CPI.

In VS Code, open the Command Palette, type >cpi, and select SAP CPI: Create a SAP CPI Groovy Script from CPI Extension.

It will prompt you to select a folder and enter a name for the project.

JohanCalderon_3-1754479898886.png

JohanCalderon_4-1754479910568.png

VS Code is listening for a connection from the SAP CPI Extension.

JohanCalderon_5-1754479957236.png

It will create a project containing the script from SAP CPI.

JohanCalderon_6-1754480055089.png

Using SAP CPI Tools Extension with trace files (Header, properties and body) - This method is the same as Using SAP CPI Tools Extension; the only difference is that the project is created from trace details in the Design iFlow section.

You need to activate the trace and run the iFlow.

JohanCalderon_7-1754480281908.png

After running the iFlow, press the Message button and then the Draw button to display all executed steps.

JohanCalderon_8-1754480499545.png

JohanCalderon_10-1754480518187.png

Double-click the Groovy script step, then click the VSCode Debug button. This will create a project containing the code from that step and add trace files for Headers, Properties, and Body.

JohanCalderon_11-1754480601890.png

JohanCalderon_13-1754480621174.png

JohanCalderon_1-1754497493639.png

Run or debug the script

JohanCalderon_2-1754497591297.png

To run or debug the project for the first time, it asks if you want to create a config.json file. This file is necessary because it contains the debug information.

JohanCalderon_3-1754497607360.png

It created a file.

JohanCalderon_4-1754497642441.png

After that, you can run or debug the code.

A print statement was added to display output in the console."

JohanCalderon_5-1754497681532.png

Create a properties file in the in folder.

JohanCalderon_6-1754497736441.png

RUN

JohanCalderon_7-1754497756121.png

When the run is finished, the result is in the out folder

JohanCalderon_10-1754497851510.png

DEBUG

Add breakpoints on lines 7, 12, and 15

JohanCalderon_11-1754497900240.png

The variables are shown on the left side

Line 7 

JohanCalderon_12-1754497927125.png

Line 12

JohanCalderon_13-1754497961336.png

Line 15

JohanCalderon_14-1754497975669.png

Ready to streamline your Groovy debugging process? Give the VS Code extension a try and see how it can simplify your development workflow. If you have questions or want to share your experience, feel free to leave a comment below! Happy coding!

6 Comments