Repository navigation
Support the Grails 9 command line for projects of Grails 9 and later - #477
Open
jdaugherty wants to merge 4 commits into
Open
jdaugherty wants to merge 4 commits into
jdaugherty wants to merge 4 commits into
Conversation
jdaugherty
force-pushed
the
feat/grails-9-cli
branch
from
November 23, 2026 16:10
2b04538 to
e493e06
Compare
Grails 9 publishes no Grails shell. Its one command line replaces the shell and the Forge CLI, and upgrade note 51 of the Grails guide tells IDEs what to do instead: run the build commands as Gradle tasks, start the command line of org.apache.grails:grails-cli with --plain-output --non-interactive, and ask help --json for the commands of a project rather than carry a list. The plugin started org.grails.cli.GrailsCli of grails-shell-cli for every Gradle project and offered a fixed list of shell commands, so a Grails 9 project had no Grails commands and no Grails run configuration. For a project whose grailsVersion has a major version of 9 or more, the Gradle import resolves the all jar of org.apache.grails:grails-cli, not transitively: that jar holds the command line and everything it needs, where the plain jar would bring the Gradle Tooling API, which Maven Central does not have. It also resolves the Grails shell of the version, which the builds of Grails 9 from before its command line still publish. That neither can be resolved is reported in the Build tool window. Projects of Grails 7 and 8 keep the shell. Which of the two runs the commands is decided by what the jar answers, not by the version, so that the plugin can be released before Grails 9.0 and used with its snapshots and milestones. The jar is started once for each jar on disk, off the event dispatch thread and for at most 30 seconds, with --plain-output --non-interactive help --json and GRAILS_PREFERRED_SHELL=forge, which the command line of Grails 9 does not read and which makes the start class of an earlier build refuse at once instead of starting the shell. A document of format 1 makes it the command line. A document of another format keeps it without completion, as does a jar that does not answer when no shell was resolved; otherwise the shell runs the commands, as for Grails 8. Every outcome but format 1 gives one notification for each project and jar. A setting of the project on the Grails settings page chooses automatic, the Grails 9 command line or the Grails shell. Commands run in the jar of the command line with those of --plain-output and --non-interactive that its document lists as its options, and with an environment or system properties typed in front of the command moved behind it, since Grails 9 refuses them there. The class started is the one the Main-Class attribute of the jar's manifest names, as the Grails wrapper of Grails 9 starts it, so that the plugin does not change when the class moves; org.apache.grails.forge.cli.GrailsCli is the fallback for a jar that names none. Completion offers the commands help --json lists in the project; the document is kept per project and asked again only when a file it depends on, the command line, the choice of it or the Gradle import changes, and the event dispatch thread never waits for it. run-app of a Grails run configuration of every Grails 9 project runs the Gradle task bootRun through the IDE's Gradle support, which debugs and stops the application as it does every Gradle task, whichever command line runs the other commands; the run-app options that bootRun has an equivalent for are mapped as the command line maps them, and the others are refused with a message. The Grails test configuration producer leaves the tests of a Grails 9 project to the Gradle test runner, and .grails/project.yml, the record of a project Grails 9 generated, marks a Grails root in the scan for roots whose Gradle import failed. The Grails 9 import tests use stand-in jars from a file repository in the test project, so the build does not depend on a published Grails 9. An import test pinned to the first published Grails 9 milestone is the follow-up, to add when that milestone exists.
jdaugherty
force-pushed
the
feat/grails-9-cli
branch
from
November 23, 2026 16:20
e493e06 to
83bd19d
Compare
jdaugherty
marked this pull request as ready for review
November 23, 2026 23:04
Contributor
Author
|
This "should" work without the forge rewrite in place, but the expectation is we'll publish this prior to the release of 9. |
…es it An environment in front of a command, as the Grails shell took it, was moved behind the name of every command: prod dbm-update became dbm-update -Dgrails.env=production. The Grails 9 command line reads -Dgrails.env after the name only for its own commands. A command of the application or of a plugin is given everything after its name as its arguments, so it ran in development with the option as one of them, which for a command that changes a database is the wrong database. The environment and the system properties typed in front of a command now go where the command takes them. A command of the command line itself still takes them after its name. A command of the application or of a plugin is run with run-command, which takes them in front of the name of the command it runs, as the Grails guide gives for another environment: run-command -Dgrails.env=production dbm-update. run-command typed by the user gets them in front of that name too, unless it names an environment there itself. A script of the application keeps them after its name, where it reads them. Which kind a command is comes from the document of help --json, which now also reads the registration of a command to tell a script. A name the document does not list is run with run-command, which runs a command the build has listed since and refuses any other name before anything runs. When the document lists no command at all, a command with an environment in front of it is refused with a message that names both forms to type, since a guess could run it in development. A command with nothing in front of it is run as typed and the document is not asked.
The Grails run configuration of a Grails 9 project ran the Gradle task by its name, bootRun, in the directory of the application. A name selects the task of that name in every project below the directory, so for a root application whose build has other applications below it, run-app started those as well. The task is now named by the path of the Gradle project of the application, as the Grails 9 command line names the tasks of the project it is run in: :bootRun for the root project and :path:bootRun for a project below it. The path is the one the Gradle import recorded for the module of the application, which Grails3Application now answers. An application whose module has no recorded path keeps the name alone.
What an application or a plugin adds to the grails command line is now a tool, and the document of help --json says more of it: startsApplication, deprecated for a tool that implements a deprecated type or lives in grails-app/commands, and deprecatedNames on the commands of grails itself. Grails9HelpDocument reads these members and falls back to defaults where a build of Grails 9 from before does not write them, so its documents and a target or registration the plugin does not know are still read. An environment typed in front of a tool of the application or of a plugin is now given through run-tool, which does not warn. run-command, still accepted, is kept as it is typed. Completion no longer offers a deprecated alias such as run-command, and offers create-tool, which the document lists in place of create-command. The messages and the README speak of tools where they mean what applications and plugins add; built-in commands stay commands. The recorded help --json fixtures have the new shape, one of the earlier shape is kept, and the document and executor tests cover both.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Grails 9 publishes no Grails shell. apache/grails-core#17114 (issue apache/grails-core#16348) replaces the shell and the Grails Forge CLI with one command line, and its upgrade note 51, "IDEs and Tools That Started the Grails Shell" (
grails-doc/src/en/guide/upgrading/upgrading90x.adocin that pull request), says what an IDE does instead:bootRun,test,integrationTest,testApp,assemble,runCommand,runScriptCommand);org.apache.grails:grails-cliand the start class its jar names, with--plain-output --non-interactive, and askshelp --jsonfor the commands of a directory instead of carrying a list of its own;.grails/project.ymlmarks a project Grails 9 generated; the version a project is on isgrailsVersion.Today the plugin starts
org.grails.cli.GrailsClioforg.apache.grails:grails-shell-clifor every Gradle Grails project and offers a hard-coded list of 34 shell commands. For a Grails 9 project the shell artifact does not exist, so there are no Grails commands and no Grails run configuration, and the list names commands Grails 9 removed. This pull request follows the contract above for projects of Grails 9 and later and leaves Grails 7 and 8 (and earlier) on the shell, unchanged.The plugin can be released before Grails 9.0. apache/grails-core#17114 is not merged: every
9.0.0-SNAPSHOTpublished until it is (such as the one in the ASF snapshot repository today) has agrails-clijar whose start class,org.apache.grails.cli.DelegatingShellApplication, hands the command to the Grails shell, which has nohelp --json, and that build still publishesgrails-shell-cli. The contract (option names, the members ofhelp --json, the start class) can also change before 9.0.0. So the plugin does not choose the command line by the version alone: it asks the jar what it is, falls back to the shell of an earlier build, and degrades to "commands run, names not completed" with one notice when the answer is not one it reads. Grails 9 snapshots and milestones can be tested with a released plugin either way.Version switch. A project is a project of Grails 9 and later when the major version of
grailsVersion(as the Gradle import records it) is 9 or more;9.0.0-SNAPSHOT,9.0.0-M1and10.xincluded. The rule is one class,GrailsCommandLineinlibs/gradle-tooling, used both inside the Gradle import and in the IDE. The.grails/project.ymlrecord does not switch it:grails project migratewrites that record for an application still on Grails 8, and the Grails 9 command line refuses such a project too. The version decides what is resolved and thatrun-appand the tests run with Gradle; which command line runs the other commands is decided as described next.Resolving (
GrailsModuleModelBuilderImpl). For Grails 9+ the tooling model builder resolvesorg.apache.grails:grails-cli:<grailsVersion>:all, not transitive, through a detached configuration, as it resolves the shell today. Thealljar is the one the Grails wrapper downloads and the distribution ships: it holds the command line and every class it needs, and its manifest names the start class. The plain jar would pull in the Gradle Tooling API, which is not on Maven Central (the same problem the shell has today). It also resolvesorg.apache.grails:grails-shell-cli:<grailsVersion>with its dependencies, exactly as for Grails 8, for the builds of Grails 9 that still have the shell. A release of Grails 9 has no shell, so a shell that cannot be resolved is not reported; when neither can be resolved, the Build tool window says so once ("Grails command line could not be resolved", naming both), and the module keeps its Grails support. The model carries the jar of the command line in a new field,commandLineUrls, next to the existingshellUrls; a project imported before this change has no command line jar in its model and runs the shell it has until it is reloaded.Which command line (
Grails9CommandLineProbe,Grails9CommandLines). For a Grails 9+ project the plugin starts the resolved jar once as a tool starts the command line,java -XX:TieredStopAtLevel=1 -cp <jar> <Main-Class> --plain-output --non-interactive help --json, with the IDE's own Java runtime, in an empty temporary directory, withGRAILS_PREFERRED_SHELL=forgein its environment, and stops it after 30 seconds. The answer is kept for the jar as it is on disk (path, size and modification time; a snapshot replaced in place is asked again), for the IDE session, and shared by all projects; it is computed on a pooled thread and never waited for on the event dispatch thread, where the Grails 9 command line is assumed until the answer is in (the jar is asked as soon as the Grails applications of a project are known, so the answer is normally in long before a command is typed). The variable matters for the earlier builds: their start class reads it and then starts the old Forge CLI, which refuses the options in about a second with exit code 2; without it, the shell they start resolves its profiles and starts Gradle, about 60 seconds outside a project and 100 inside one, and ends with exit code 1. The Grails 9 command line does not read it (its upgrade notes say so, andGrailsCliSpectests it). The answer is one of:help --jsonlists in the project;formatis another number: the Grails 9 command line of a later contract; commands still run there, without completion;When the Grails 9 side changes. Every outcome other than format 1 gives one notification (group "Grails command line") for each project and jar, never one per keystroke or per command: that the plugin uses the shell of an earlier build (information), that the document is of a newer format and the plugin needs an update, that the jar does not answer and there is no shell, or that the listing of a project's commands failed later (warnings). Each has an action that opens the setting. The document's members the plugin does not know are ignored (as before). The global options the plugin gives every command are taken from the document's own
options: of--plain-outputand--non-interactive, those it lists; both when the document has nooptionsmember, has not been read yet, or cannot be read. The start class stays the one the manifest names.Setting (
GrailsCommandLineSettings). Settings ▸ Languages & Frameworks ▸ Grails has a new choice, Command line of Grails 9 projects: Automatic (the default, as above), Grails 9 command line (whatever the jar answers; it is still asked, for the global options and the completion) or Grails shell (the jar is not asked; without a resolved shell no command runs). It applies to the project's applications of Grails 9 and later only, is kept per project in the workspace file (GrailsCommandLinestate), and a change drops the cached command lists. README.md describes it.Running commands (
Grails9CommandExecutor). Commands of a Grails 9 project on the Grails 9 command line (Run Grails Command, the New Controller/Service/... actions,generate-*, a Grails run configuration with any command butrun-app) start thealljar with the global options above and-XX:TieredStopAtLevel=1(what the distribution's start scripts give a command). The class started is the one theMain-Classattribute of the jar's manifest names, read each time a command starts, as the Grails 9 wrapper starts it: the start class has moved fromorg.apache.grails.cli.GrailsClitoorg.apache.grails.forge.cli.GrailsCliin apache/grails-core#17114 (the jar built from it now names the latter), and reading the manifest keeps the plugin working across that move and any later one.org.apache.grails.forge.cli.GrailsCliis used only for a jar whose manifest names no start class (or cannot be read). The shell's spellings that Grails 9 refuses are translated: an environment or-Doptions in front of the command (prod war,-Dx=y run-app) move behind it, the environment as-Dgrails.env=production(upgrade note 43).Grails3InstallationCommandExecutor, whose SDK layout Grails 9 does not have, claims a Grails 9 project only when its commands run in the shell.Command list (
Grails9HelpDocument,Grails9CommandCatalog,Grails9CommandProvider). Completion in Run Grails Command offers the names and aliasesgrails help --jsonlists in the project: the built-in commands the project's record allows, the commands of the application and its plugins thatgrailsCommandCataloglisted, and the scripts. Only a jar that answered format 1 is asked in the project. The document (format 1) is cached per project and asked again only when it can be out of date: when one of the files the answer depends on changes (.grails/project.yml,.grails/forge.lock.yml,.grails/cache/command-catalog.json,grails-forge-cli.yml,grails-cli.yml,gradle.properties,src/main/scripts,grails-app/commands), when the command line's class path or version changes, when another command line is chosen, and after a Gradle reload or a recomputation of the Grails applications. A failed listing is cached as empty until then, so a broken command line is not restarted on every keystroke. The event dispatch thread never waits: it gets the document known so far while a newer one is fetched in the background; completion, which runs off it, waits cancellably. The dialog prefetches the document when it opens. A run ofhelp --jsontakes about 0.4 s.Run configuration (
Grails9RunApp). For every Grails 9 project, whichever command line runs its other commands,run-appof a Grails run configuration runs the Gradle taskbootRunthrough the IDE's Gradle support, in a run of its own (named after the configuration), with Run and Debug both supported; the run configuration hands it over before it asks for an executor, so a project whose commands have nothing to run in still runs its application. I chosebootRunover starting the CLI'srun-app:bootRunforks, on a port of its choosing. Through the CLI it would needrun-app --debug-jvm, a fixed port 5005 that suspends, and the plugin's current debug path for the shell (GRAILS_FORK_OPTS) is not read by Grails 9.run-appwrites.grails/run/app.jsonforgrails stop-app.bootRunwrites none, sograils stop-appin a terminal does not stop an application the IDE started, which is what the Grails guide says for./gradlew bootRun; the IDE's Stop is the way to stop it.The options of
run-appthatbootRunhas an equivalent for are given as the command line gives them: the environment (defaultdevelopment) as-Dgrails.env,--port/--host(also with one dash or=) as-Dgrails.server.port/-Dgrails.server.address,-D/-Pas they are, and everything after--to Gradle.--debug-jvmis dropped (use Debug). Options only the CLI has (--https,--detach,--foreground,--ready-timeout,--query-tail,--verbose) and VM options (which would reach the Gradle daemon, not the application) are refused with a message that says what to do instead. "Launch browser" is kept: a project-levelExecutionListenerattaches the existing browser-launch listener to the Gradle run when the application printsGrails application running at .... A Grails 9 project is runnable (GrailsRunConfigurationType.isRunnable) even when neither command line could be resolved, sincebootRunneeds neither.Tests of the application. The Grails test configuration producer no longer offers its
test-appconfiguration for a Grails 9 project, whichever command line it has (the Grails 9 command line has nointellij-command-proxyto run it through); the IDE's Gradle test runner runs those tests, as for any Gradle project.Detection. Grails 9 projects are recognised as before, from the Grails Gradle plugin the import finds (the plugin ids are unchanged in Grails 9) and their
grails-appdirectory, which every application type Grails 9 generates has..grails/project.ymlis recognised (Grails9Projects) as the record of a Grails 9 project, and marks the root of a Grails project in the scan that reports Grails roots whose Gradle import failed (GrailsGradleSyncStatus), as the Grails 9 command line treats it. It does not switch the version (see above).The new-project wizard (hosted Forge API) is not changed. README.md and IMPROVEMENT-PLAN.md (2.6) describe the Grails 9 behaviour, the fallback and the setting.
How it was tested
New tests, in the plugin's test framework:
Grails9CommandLinesTest(13): the choice of the command line, with real jars the test writes and the plugin starts as a process (FakeGrailsCommandLines, whose start class is a small class of the test sources): a jar that answers format 1 is the command line (asked once, with--plain-output --non-interactive help --jsonandGRAILS_PREFERRED_SHELL=forge), with its completion and no notice; one that answers format 2 stays the command line, without completion, with the contract's global options and one warning; a stand-in for the earlier builds (exit 2 at once withGRAILS_PREFERRED_SHELL=forge, two minutes without it, which also shows the variable is passed) gives way to the shell, with the shell's commands and one notice naminggrails-shell-cli; one that does not answer within the time (2 s in the test) gives way to the shell; without a shell, a jar that is not the command line keeps it without completion; one notice for each jar however often executors, completion and listings are asked across two applications, and another for another jar; a jar is asked once until it is replaced; the event dispatch thread does not wait for a jar that takes 3 s; the global options from the document (both, only--plain-output, none listed); the setting forcing the shell (the jar not asked) and the command line (for a jar that does not answer); the setting leaving Grails 8 alone;run-appstaysbootRunwith nothing to run commands in.GrailsCommandLineSettingsTest(4): automatic by default, kept through serialization, an unknown stored value read as automatic, a change told once.Grails9ProjectsTest(7): the version switch by the major version ofgrailsVersion(snapshots, milestones and 10.x included; 8.x, 7.x and malformed versions excluded); the.grails/project.ymlrecord and what is not one; a Grails 8 project with a record keeps the shell; a Grails 9 project without one gets the Grails 9 path.Grails9CommandExecutorTest(8): which executor a Grails 9 and a Grails 8 project get, and a Grails 9 project with a shell and no command line jar on disk gets the shell; the Java parameters (thealljar alone on the class path, nograils-rt,--plain-output --non-interactivefirst,-XX:TieredStopAtLevel=1, the project as working directory, the command's VM options); the start class read from the manifest of jars the test writes (the new class name, the earlier one, the first jar that names one, and the fallback for a jar withoutMain-Class, a file that is no jar and a missing file); an environment and properties in front of the command moved behind it; an unresolved command line reported while the project stays runnable.Grails9RunAppTest(10): thebootRunarguments forrun-appand its options, the refused options and VM options, and the Gradle run settings.Grails9HelpDocumentTest(9): two documentsgrails help --jsonwrote, recorded in a web application created withgrails create-app com.example.shopby the command line built from Make Grails Forge the one generator and grails the one command line grails-core#17114 (9.0.0-SNAPSHOT), before and after./gradlew grailsCommandCatalog(plugin/testdata/grails9/help-json, the project path replaced by/home/me/shop; the second keeps the commands but not their options, to keep it small); the refusal of another format; a later format told apart from output that is no document; the options of the command line itself; members the reader does not know.Grails9CommandCatalogTest(11): completion from the document; the command line asked once while nothing changes, and again after a change tocommand-catalog.json, a script, the record, the command line's version, the choice of the command line, a Gradle reload or a recomputation of the applications; a failed listing kept, with one notice over two failed listings; a listing of another format not read; the event dispatch thread answered at once with the document known so far; no listing for a Grails 8 project.GrailsCustomFoldersConfigurableUiTest(+1): the settings page opens on the stored choice, offers the three, is modified by another choice and stores it.GrailsGradleSyncStatusTest(+1) andGrailsRunConfigurationProducerTest(+1): the record marks a blocked Grails root; no Grails test configuration for a Grails 9 project. Both fail with the change reverted.GradleApacheGrailsImportingTest(+3): a real Gradle 9.8.0 import with the Grails Gradle plugin 8.0.0-RC2. All three use thegrailsVersionof a Grails 9 version that is never published, against a file repository in the project: with the command line only, the model holds exactly thealljar (the stand-in POM names a dependency the repository does not have, so a transitive resolution would fail) and no shell, and nothing is reported; with the command line and a shell, the model holds both, the stand-in jar (no jar at all) answers nothing and the shell executor is chosen; with neither, the Build tool window reports "Grails command line could not be resolved" while the project stays runnable. No test resolves a published Grails 9 build. The follow-up is an import test pinned to the first published Grails 9 milestone, to add when that milestone exists (IMPROVEMENT-PLAN.md 2.6); a check against the Grails 9 snapshots, if wanted earlier, belongs on a schedule rather than in every build.Runs:
GrailsRunTargetCompletionTest,GrailsRunConfigurationTypeTest,GrailsCommandLineExecutorTestandGrailsCustomFoldersConfigurableTest) pass../gradlew test: 1568 tests in 251 classes, 0 failures, 0 errors, 0 skipped, including the Gradle import tests for Grails 3.3.1, Grails 6 and Grails 8.0.0-RC2. That run still had an import test of the published9.0.0-SNAPSHOT, which this pull request no longer has, so the suite now has 1567../gradlew ratpasses.By hand, against the two real jars:
grails-cli-9.0.0-20261123.015441-38-all.jarof the ASF snapshot repository (from before Make Grails Forge the one generator and grails the one command line grails-core#17114;Main-Class: org.apache.grails.cli.DelegatingShellApplication), started with--plain-output --non-interactive help --json: withoutGRAILS_PREFERRED_SHELLit ends with exit code 1 and no JSON after 63 s in an empty directory and after 103 s in a Grails 9 application (where it downloaded a Gradle distribution and started Gradle); withGRAILS_PREFERRED_SHELL=forgeit ends in 1 s with exit code 2 and "Unknown options: '--plain-output', '--non-interactive', 'help', '--json'". The plugin's code (the probe and the choice, run against the jar) classifies it in 1.1 s as not the command line and picks the shell executor when the shell is resolved, and the Grails 9 executor without completion when it is not.alljar built from Make Grails Forge the one generator and grails the one command line grails-core#17114 (Main-Class: org.apache.grails.forge.cli.GrailsCli): it answers format 1 in under a second in an empty directory and in an application it created (create-app com.example.shop), withoptionslisting-h/--help,--non-interactive,--plain-output,-x/--stacktrace,-v/--verboseand-V/--version, with or withoutGRAILS_PREFERRED_SHELL=forge. The plugin's code classifies it in 0.43 s as the command line and starts commands with--plain-output --non-interactive.alljar of Make Grails Forge the one generator and grails the one command line grails-core#17114 (then still namingorg.apache.grails.cli.GrailsCli):create-controller com.example.Book, started as the plugin starts it, writesBookController.groovyandBookControllerSpec.groovy;prod warwith the environment in front ends with exit code 2, which is why the plugin moves it behind the command;./gradlew bootRun -Dgrails.env=development -Dgrails.server.port=18080, the Gradle arguments the plugin gives forrun-app --port 18080, starts the application on port 18080 (HTTP 200), which prints the line the browser launcher looks for, and cancelling the Gradle run ended it.Not run: the Plugin Verifier, the Community Edition tests (
testIdeCe) and the sandbox IDE.What is not done
runIde), and Debug ofbootRun, Stop, the browser launch, the completion in the dialog, the notifications and the settings page were not exercised interactively. The hand-off to the Gradle run (ExternalSystemUtil.runTask) is not covered by a test; its settings are. That the run configuration handsrun-appof a Grails 9 project tobootRunbefore it looks for an executor is covered throughGrails9RunApp.runsAsBootRunandisRunnable, not throughgetState/checkConfigurationthemselves.test-apptyped into Run Grails Command or a Grails run configuration for a Grails 9 project on the command line runs through it (gradlew testApp) as plain console output, without the test tree.featureandproject, option names, or descriptions, whichhelp --jsonhas; nor does the plugin offer to rungrailsCommandCatalogwhen the document says the application's commands are not listed yet.bootRunis given no JVM options of the run configuration; they belong tojvmArgsofbootRuninbuild.gradle.