Skip to content

Execute Groovy Script

Groovy itself can naturally support Java code, so DebugTools can write Groovy code and run it based on the attached application.

Position

ToolsWindow

Click the toolbar on the right side of Idea to wake up the DebugTools window. Click G on the left to open the Groovy console.

groovy_tools_window

Right-click Menu

In the Idea main window, invoke the right-click menu and click the Groovy Console button to open the console.

groovy_console_menu

Write

After clicking the Groovy controller, a console.groovy file will be created in Idea -> Project -> Scratches and Consoles -> Debug Tools Plugins -> groovy, where you can write Groovy code and run it.

groovy_position

Write the Groovy code to run. You can click the complete example code below to view it.

groovy_console

Why create a file?

Convenient. When writing, idea can provide groovy code prompts, and can also prompt the code according to your current project.

Run

In the console.groovy file, invoke the right-click menu and click the Run 'console.groovy' With Debug Tools button. DebugTools will run the script with the attached application.

groovy_run_menu

Result

The running results will be displayed in a pop-up at the bottom, and the toString and debug methods are provided for viewing.

groovy_run_result