DC-Grails-VS
Version 0.1.31 is a pre-release. To install it, open the Marketplace page above
and choose Switch to Pre-Release Version, or from the command line (the
Grails and Gradle commands from the command palette and a sidebar tree — and a debugger that can actually stop on a line of Groovy. Breakpoints in
|
| Setting | Default | What it does |
|---|---|---|
grails.run.command |
"" |
Command line to start the app instead of the Gradle wrapper. For projects that boot through a script which exports the environment the app needs. |
grails.run.debugCommand |
"" |
Same, for Debug App. Defaults to grails.run.command with --debug-jvm appended. |
grails.run.env |
{} |
Environment variables to add for the app process. |
grails.run.args |
[] |
Extra arguments for bootRun. |
grails.debug.adapter |
groovy |
groovy uses the adapter in this extension. java hands the session to vscode-java-debug, which cannot bind a breakpoint in a .groovy file. |
grails.debug.javaPath |
"" |
The java used to run the debug adapter. Defaults to the discovery order above. |
grails.debug.evaluate.watchRunsCode |
true |
Whether a Watch may run code in the application (see Expressions). Watches are re-evaluated at every stop, so one with side effects runs again each time. |
grails.debug.evaluate.timeoutMs |
5000 |
How long an expression run in the application may take before the debugger looks for what is blocking it. |
Attach configurations also take sourcePaths (roots for resolving stack frames,
defaulted from the project layout), stepFilters (packages to step over),
stepIntoProjectCodeOnly and trace.
Stopping
Stop reaches the application, not just the build. Gradle forks the app from its daemon, and the daemon is reused between builds, so the app is only sometimes a descendant of the process this extension started — killing that process tree leaves the app running about as often as not, holding the debug port and 8080. Stop kills the tree and, separately, whatever JVM is listening on the ports the app announced.
Debug App also checks the debug port before starting. If something already holds
it, it says what, and offers to stop it — because a JVM that cannot open its debug
port produces a build that stops after :findMainClass and prints nothing at all,
which is indistinguishable from a hang.
Hover and watch
Hovering a name shows its value, and watch expressions work, for anything that is
a path: user.name, params['id'], items[0].label, this.someService. Names
from the Grails scope resolve too, so params and request work in a hover even
though neither appears in the source.
Read, not run. A method call, an operator or a closure needs an expression compiled and executed inside the application, which means resuming its threads to do it -- so those are refused, by name and with the reason, rather than reported as missing.
Logpoints and hit counts
Right-click in the gutter for Add Logpoint: a breakpoint that prints and carries on rather than stopping. Anything in braces is read the way a hover is, so
iteration {i}, so far {doubled}, from {params.id}
prints iteration 2, so far [105, 106], from 47. Lists and maps are written out
rather than shown as an object id — up to eight entries, two levels deep. An
expression it cannot read prints the reason in place of the value instead of
disappearing.
Hit Count takes a number, optionally after an operator:
100 |
stop from the hundredth hit onward (same as >=100) |
=100 |
stop on the hundredth hit only |
>100 <100 <=100 |
as they read |
%10 |
stop on every tenth hit |
The count is of hits that would have stopped, so the second copy Groovy compiles of every line does not advance it. A hit count that cannot be read is reported on the breakpoint rather than ignored.
Expressions
Watch, hover, the Debug Console, conditions and logpoint {...} all take Groovy
expressions. What can be answered by reading the stopped frame is answered that
way, with nothing run in the application:
total + 1 a / 8 x > 3 && user != null user?.name ?: 'anonymous'
items.size() name.length() list.isEmpty() list[-1] params.id == '5'
Names from the Grails scope work too: params.action == 'index' although params
is not a local of anything on the stack. Decimal literals and / follow Groovy
(0.1 + 0.2 is 0.3, 100 / 8 is 12.5).
What reading cannot answer — other method calls, closures, GORM, string
interpolation — is run in the application with its own Groovy, in the Debug
Console and (unless grails.debug.evaluate.watchRunsCode is off) in Watch:
label.toUpperCase() items.find { it.active } Book.countByTitle('x') "t=${total}"
A bare field or method name means what it means in the source, this is the
stopped object (the enclosing one inside a closure), and application classes can be
named. While it runs, breakpoints are off, so the evaluation never stops on one.
A hover never runs code, and an assignment is never run (change values in the
Variables panel).
Running code while the application is stopped can wait for a lock another stopped
thread holds. After grails.debug.evaluate.timeoutMs, that thread alone is resumed
to free it and the Debug Console says so: the application is then no longer fully
paused. When nothing explains the wait (another stopped thread part-way through
loading a class does this), the evaluation is reported as stuck with where it is;
Continue lets it finish.
Conditions
The Condition box takes an expression, read as described above: comparisons,
&& / || / !, arithmetic, size() and the like. Conditions do not run code in
the application yet. One that would need to — a call, a closure — is reported on the
breakpoint when it is set, and that breakpoint then stops every time. A
condition quietly treated as false would be a breakpoint that never fires, which
reads as a broken debugger rather than as a condition to rewrite.
With a hit count as well, the count advances only when the condition was true:
i > 1 with =2 stops the second time i > 1 holds.
Data breakpoints
Right-click a field in the variables pane and choose Break on Value Change. The debugger stops where the write happens and says what the value was and what it is about to become:
dapspike.SpikeService.touches: 0 -> 1
Watching a field is a JVM facility, so nothing runs in your application to arm one. It watches the object you pointed at rather than every instance of the class, which is what "this variable" means in the pane. Reads can be watched too where the JVM allows it.
Only fields can be watched — that is all the JVM reports writes to — so the option does not appear for a local, an array element or a map entry, and a final field is refused because it is never written again.
Changing a value
A local, a field, an array element or an existing map entry can be changed from
the variables pane while the target is stopped: numbers, strings, booleans and
null. Setting seed from 4 to 7 at the top of a service method changes what the
application then returns.
A local that a closure captured is written inside the groovy.lang.Reference it
is boxed in, not over it — replacing the box would leave the closure holding the
old one. A map entry is changed in place; a key that is not there cannot be added
this way.
This is the one place the debugger runs code in your application. JDI will not put
an int into a slot typed java.lang.Integer, and Groovy types nearly everything
that way, so making a boxed number calls valueOf on the box class — a JDK static
that takes no locks — single-threaded. Reading a value never runs anything.
Explain an exception
Requires VS Code 1.90 or later. When paused on a Groovy exception, click Explain Exception in the status bar or run Grails: Explain Exception. Choose one of the language models available in VS Code. The explanation streams into a read-only document beside your code and includes the context used.
The request sends the exception type/message, up to twelve application frames, and nearby source from up to three workspace files. It does not collect locals, Grails request/session values or environment variables. Source and exception messages can themselves contain sensitive text; Grails: Show Exception Context lets you inspect the local snapshot before choosing to use a model. No data is sent automatically when a breakpoint is hit. The snapshot uses current editor text (including unsaved changes), which may differ from a deployed application.
Model access and any initial consent are handled by VS Code's Language Model API. No particular model or vendor is required. If no model is available, the command opens the local exception context with setup guidance. Cancel the progress notification to stop a request; continuing or stepping the debugger also cancels it. Explanations suggest changes but do not edit files or execute application code.
For coding agents (MCP)
The same debugger is an MCP server, so an agent such as Claude Code can debug a running Grails app itself: attach, set breakpoints, send a request, wait for the stop, read the stack and variables, evaluate, step and continue.
claude mcp add --transport stdio --scope project groovy-debug -- \
java --add-modules jdk.jdi -jar <path to>/groovy-dap.jar --mcp --workspace "$PWD"
groovy-dap.jar is in the extension's install folder
(~/.vscode/extensions/gaolei8888.grails-gradle-extension-<version>/dist/) or in
dist/ of a build of this repository. Options:
| Option | Default | |
|---|---|---|
--allow-port N |
5005 |
A JDWP port attach may use; repeat for more. |
--allow-run-code |
off | Let evaluate run code in the app (calls, closures, GORM). Off, it only reads. |
--workspace DIR |
current directory | The project: relative paths and default source roots. |
Tools: attach (with resume: false the app is held at its start until
continue, so start-up code can be stopped in too), set_breakpoints,
trigger_http (sends the request in the background; a stopped app never answers a
plain curl), wait_for_stop, stack, variables, evaluate, continue, step,
status, detach. Only this machine can be attached to, and HTTP requests go to
this machine only. Start the app with ./gradlew bootRun --debug-jvm; a VS Code
debug session on the same JVM cannot run at the same time (JDWP serves one
debugger).
Not yet: masking passwords and tokens in what is read, an automatic continue after a long stop, and pausing only the stopped thread.
Development and tests
Run pnpm install, npm run build:server, pnpm test, and pnpm lint.
The debug adapter has its own dependency-free checks: cd server && ./gradlew verifyProtocol (also run by ./gradlew build).
pnpm test:editor runs the real VS Code/Grails integration suite in an isolated
profile. See testing instructions for the standalone testbed,
environment overrides and test coverage.
Known issues
- Step over once skipped code. It was reported that after stepping over the last line of a service method back into the controller, a further step over skipped the remaining code. It could not be reproduced afterwards (several target shapes, JDK 21 and 25, Grails 7 and 8), and the cause is unknown.
- Step into a
@Transactionalmethod enters it (scripted runs on Grails 7.2.3 and 8.0.0, 2026-10-12). Inside a.eachclosure, Step Into stops in the closure for the first iteration only and then continues past the loop; put a breakpoint in the closure to stop on every iteration. Step Into relies onsourcePathsbeing the project's source roots (the extension fills these in): with the application folder itself as the only root, Step Into does not enter calls. - Conditions and logpoints only read (see Expressions); an expression there that would need code run in the application is refused, with the reason. Watch and the Debug Console run such expressions; a hover never does.
- Comparing two different objects with
==is refused when reading (it would runequals()); in the Debug Console it runs. - Simple variable values can be changed in the Variables panel: numbers,
true/false, characters, strings andnull, written as literals. A number put into a boxed orObjectslot is made by runningvalueOfof one of the JDK box classes in the application. Not supported: objects and collections. Editing from Watch (setExpression) is deferred. Changing a value was seen working in a real VS Code window with the earlier adapter; which request VS Code sends for it is not known. - Hot reload needs a recompile. Saving a source file alone does not change the running app. Once the class was reloaded (what triggers that was not established), breakpoints rebound to the new class and showed the new value; seen in one scenario in a real window.
- Step Into with nothing to enter does nothing. On the last line of an action it stays on that line; Step Out or Step Over there lets the request finish without stopping in framework code.
- Stop while paused: if the JVM is stopped at a breakpoint, Stop only ends the Gradle client; the application and the adapter stay until you Continue.
- Stopping kills any
javaprocess listening on the debug port (5005), which Gradle hard-codes. - Code Groovy's own classpath script may print
Cannot mutate the state of configuration ':compileOnly'in its output channel on Grails projects; it is harmless and not from this extension. - Two different applications serving the same view path in one JVM would make a GSP breakpoint ambiguous; it binds to neither rather than guessing.
- The AI command's real exception capture and no-model behavior have been tested in VS Code. Model streaming/error/cancellation paths have automated tests with a simulated provider; a live provider response still needs verification.
Star it
If you use this, clone it, or build something of your own on top of it, please star the project on GitHub. It takes one click, and it is the main way anyone else finds out this exists.
License
MIT