Repository navigation
Split CLI dependencies from the runtime classpath - #15948
Conversation
a7d2537 to
01ddd85
Compare
|
These were resolving locally due to having maven local search on; I need to fix the dependency substitution to fix these resolution issues. |
|
Turns out there's a real build issue separate from this change, micronaut-singleton isn't including our functional test app so it was pulling from upstream instead of testing with the local copy. |
|
The published Gradle Module Metadata still contains capability-style dependencies (org.apache.grails:grails-core + requireCapability('org.apache.grails:grails-core-cli')) — violating the split's design rule that external consumers must see the plain -cli coordinate, never capabilities. When Gradle resolves that from a Maven repo, it selects grails-core's cliRuntimeElements variant, follows its available-at redirect to the standalone grails-core-cli module, and then sees both nodes providing the same capability — a self-conflict. I reproduced it with a one-dependency project against build/local-maven, and it fails with both timestamped and non-unique snapshots, so it's not a snapshot-timestamp issue. There are two distinct leak paths:
I'm still researching possible solutions for this one. |
|
This is now fixed. We have to support cases where the library is a regular library imported by another project that uses the requireCapbility - this is only when the projects are defined in the same build. I've created a dedicated plugin for this scenario. |
codeconsole
left a comment
There was a problem hiding this comment.
This is the right architecture for the CLI split, and most of the execution is excellent for a 260-file change: the renames are mechanically clean (h5/h7 command twins verified line-identical modulo package, no grails.dev.commands stragglers outside migration docs, license headers preserved), the BOM enumerates companion coordinates automatically via the lazy cliArtifactId sweep so there is nothing to keep in sync by hand, the AST transform ordering is verifiably correct with the ConfigReportCommand bootstrap problem cleanly solved, the docs match the implemented behavior including an honest upgrade note on the clean break, and the grailsCli configuration scoping is right (compile/test visible, absent from runtimeClasspath/bootJar/bootWar). The long-standing Groovy-conflict TODO in the dbmigration builds is genuinely resolved rather than papered over.
I left inline comments on the issues I think need resolution before merge — the two blocking ones are the project-dependency companion wiring in GrailsCliGradlePlugin and the 1.0.0-SNAPSHOT of grails-publish flowing into the published BOM. Details and suggested fixes are on the relevant lines.
A few minor items not worth their own threads:
GrailsApplicationContextCommandRunner's pre-existingCommand not found for name: ...message is now the symptom users will see when a companion was not provisioned; mentioning thegrailsCliconfiguration /-cliartifact in that message would save support traffic.FactoriesFileWriter.addToPropscarries over the old substring-based dedup check (existing.contains(classNodeName)), which miscounts when one FQCN is a prefix of another. Pre-existing, not a regression, but this refactor was the natural moment to fix it.- Four spring-security command files lost their
@author Puneet Behljavadoc tags during the rename (e.g.S2QuickstartCommand) — worth confirming that was intentional.
|
fixes #15377 |
|
@jamesfredley I'd like to make sure you're ok with the direction this PR takes. Can you review this before Sunday so we can possibly stage the next milestone? |
davydotcom
left a comment
There was a problem hiding this comment.
The overall intent of this PR is quite needed. This has been a problem for a while. Code looks good and while the file changed count is high. Most of that is due to classpath package changes. There are some adjustments that may be merited in a future PR but I dont see anything majorly wrong here. We have a tendancy here to let AI help us review PRs like this and that is awesome but they also can tend to point out issues out of scope or non critical to a merge. It is up to us to take a human look at it first and assess what those agents say if its needed or not. I approve this PR with hte understanding we may have some iteration on future grails 8 point releases to improve edge cases.
Resolve conflicts by keeping CLI companion-artifact changes alongside Hibernate 7 forge selection and plugin bean lifecycle docs from 8.0.x. Co-authored-by: Cursor <[email protected]>
|
@davydotcom everyone understands AI is not perfect, but if it is going to speed up the time in getting PRs reviewed, I am 100% for it. We need to move things forward at a MUCH faster rate. Grails has notoriously been wayyy behind on the development cycle and in a constant state of catch up. The fact that it took this simple PR a week to get evaluated showcases this problem. I invite anyone willing to spend money on tokens on a top tier model to spend some on any PR. Those comments were generated with Fable and done a week before anyone else set eyes on it. It was just meant to get things moving forward. You are literally responding today to something generated a week ago. |
|
Didn't say it wasn't |
awesome, glad you are onboard. Don't get me wrong, I definitely appreciate all your feedback and contributions. |
|
I am for this and the PR looks fine. But I would want to know the clear path for end apps to quickly upgrade to Grails 8, which they will need to do, when we GA 8.0.0, due to Spring Boot EOL. Will they have to wait on common plugins to re-release and will that bottleneck upgrading to Grails 8. |
I suspect the breaking part of this PR is only the command part. So from an upgrade perspective, that is likely the only blocker. With that said, we've already made changes to 8.x that will likely break plugins (due to spring boot4 changes). Based on the above, I'm assuming if the core plugin code continues to function, then that's probably good enough to merge. |
|
@scott @davydotcom @jamesfredley I know @jamesfredley brought up purchasing AI credits for key contributors. We should have a wider discussion about this in the weekly. If AI helps us get the reviews done easier, I'm for it. What my concern is is AI generating 100's of PRs that then no one but AI reviews. That's what often gets categorized as "AI Slop" and it can lead to contributor time being wasted. Another way to say this: if AI helps accelerate contributions, great. If AI helps accelerate only commits and then not reviews, it's a major problem for us. |
jamesfredley
left a comment
There was a problem hiding this comment.
Third-party plugin authors: this is the heavy part of the migration
The PR description says most applications upgrade with no build changes, which is accurate for apps. But that promise rests entirely on the plugin ecosystem being rebuilt for Grails 8 first, and the migration burden that lands on third-party plugin authors is worth calling out explicitly in the upgrade notes.
An unchanged Grails 7 command plugin dropped onto a Grails 8 app is not command-compatible - and it fails silently. Three independent reasons, each sufficient on its own:
- Its
META-INF/grails.factoriescommand entries are never read -ApplicationContextCommandRegistrynow loads onlyMETA-INF/grails-cli.factories. - Its command implements the now-absent
grails.dev.commands.*contract (moved toorg.apache.grails.core.cli.*, no forwarding alias). - Its runtime jar lacks the
Grails-Cli-Artifactmanifest attribute that the app-sideGrailsCliGradlePluginscans for during companion auto-discovery.
The plugin's non-command functionality may keep working, but all of its commands disappear with no error and no warning. There is no transition path where the old packaging keeps working - it is a hard break, not a deprecation.
The supported migration is not a recompile; it is a repackaging with a second published artifact:
- Apply
org.apache.grails.gradle.grails-plugin-cli. - Move command sources to
src/cli/groovy. - Rewrite the contract imports (
grails.dev.commands.*->org.apache.grails.core.cli.*). - Move CLI-only dependencies to
cliApi/cliImplementation. - Rename hand-authored registrations from
META-INF/grails.factoriestoMETA-INF/grails-cli.factories(generated registrations need no file). - Publish the companion
-cliartifact alongside the plugin.
Request: since the silent-failure mode is the most user-hostile part, it would help to (a) state prominently in the upgrade notes that unchanged 7.x command plugins lose their commands silently, and (b) consider emitting a build- or runtime-time warning when META-INF/grails.factories still contains ApplicationCommand registrations, so the failure is diagnosable instead of invisible.
Line-level comments follow for the specific correctness bugs found in the new machinery.
|
I was testing grails-web-console with this code line and seeing what the breakage would be since it doesn't have commands. I can confirm that the plugin should work, but I did find a specific issue on the web console plugin. We removed the get/getAt methods on Metadata as part of the early 8.0 deprecation work. This means the following breaks your app now, unless you fix it:
Older grails apps would have generated using this syntax. To @jamesfredley original point, this change is only breaking for the command portion. plugins continue to work with this implementation otherwise. |
findAdvertisedCliArtifact returned a bare group:artifactId coordinate for a companion advertised by a project of the same build, so autoProvisionCliDependencies added it as an external module dependency — sending Gradle to a repository for a sibling project's not-yet-published cli variant. Bind a current-build companion as a project dependency requesting its cli feature capability instead, and keep the module coordinate path for external and included-build components. Warn when the discovery probe resolves leniently with failures so dropped companions (and their per-command tasks) are not silent. Add CliAutoDiscoverySpec and the cli-companion-autodiscovery test project covering the project-capability wiring, the guarantee that grailsCli never leaks onto the runtime classpath, and the cliAutoProvision opt-out.
…dentity FactoriesFileWriter deduplicated registrations with a substring contains() test, so two commands whose fully-qualified names are prefixes of one another (Foo vs FooCommand) collided and the second was silently dropped from the factories file. Dedup on exact membership instead, and pin the factories write to ISO-8859-1 to match Properties.load and the reproducible-build rewrite. FactoriesFileWriterSpec drives the registration end-to-end: concrete subtype registered, abstract base excluded, prefix-named commands both kept. The companion -cli constraints were declared only on grails-base-bom, but enforcedPlatform() enforces a platform's direct constraints, not those inherited via platform(). An app pinning versions through enforcedPlatform(grails-bom) received the unversioned *-cli dependencies added by auto-provisioning and failed to resolve them. Extract the companion-constraint enumeration into a shared script applied to the base and every derived BOM, so all of them carry the constraints directly. Companion discovery now matches a project component to a project of the consuming build by build tree path instead of assuming the current build is the root build, so discovery works when the consumer itself is an included build and never binds to a same-path project of the wrong build.
The cli feature variant kept only the Gradle-computed default capability
(group:name-cli), so an in-build consumer requiring the advertised coordinate of a
companion customized with cliArtifact { artifactId = ... } failed to resolve, and
the published-metadata rewrite only recognized the <module>-cli naming convention,
which would have leaked the capability request into the GMM for customized
coordinates. Customized companions now carry the advertised capability alongside
the default, the rewrite also retargets capabilities matching a companion
advertised by a project of the build, and companion discovery reads the
cliArtifact extension when the producing project's afterEvaluate has not exported
the coordinate property yet.
Covered end to end with a customized acme companion in both test projects:
in-build discovery and resolution through the advertised capability, and
publish/external-resolve with plain coordinates in the pom and module metadata.
FactoriesFileWriterSpec also gains the indirect-implementor case (a command
implementing the contract through a trait).
The upgrade notes and What's New covered the mechanics of the companion-artifact split but not its bounded impact on upgrading: plugins without commands are unaffected, command-bearing plugins keep their runtime functionality until re-released (only their commands are unavailable), and the application's own commands need only the import rename. Also document the cliArtifact artifactId customization and its capability semantics.
|
@jamesfredley following up on the upgrade-path question: the docs now spell out the bounded impact (upgrade notes §35 "What this change means for upgrading an application" + What's New). Verified empirically as well — a Grails 7 plugin (grails-web-console 7.1.0) runs on a Grails 8 app built from this branch with its runtime functionality intact; the split itself required no plugin changes. Plugin re-releases are only needed for commands (companion |
|
@jamesfredley Given that:
I'm going to merge this after the tests finish. If you feel this needs reverted, let's revisit. |
The arguments/options example read `commandLine.args`: a command has no `commandLine` property (the GrailsApplicationCommand trait exposes `executionContext` and an `args` getter for the remaining arguments), and `--`-prefixed flags are parsed as options rather than remaining arguments, so the example failed at runtime as written. Use the trait's `args` getter and `executionContext.commandLine.hasOption(...)`, and correct the surrounding prose to name `handle()` instead of `run()`.
✅ All tests passed ✅🏷️ Commit: d6d49e8 Learn more about TestLens at testlens.app. |
PR apache#15948 split the CLI command tier off the application runtime classpath. As part of that split the command contract moved from grails.dev.commands.* to org.apache.grails.core.cli.* (with no forwarding alias) and command registration moved from META-INF/grails.factories (key grails.dev.commands.ApplicationCommand) to META-INF/grails-cli.factories. The result is that an unchanged, already-published Grails 7 command plugin silently loses all of its application commands on Grails 8: the command classes no longer link and their factory entries are never read. This adds a deprecated compatibility layer that lives entirely in the grails-core-cli tier (so the runtime classpath split is preserved) and lets unchanged Grails 7 command plugins keep working without a re-release: - Restore the deprecated grails.dev.commands.* command contract (ApplicationCommand, GrailsApplicationCommand, ExecutionContext and the io/template helpers) so pre-compiled Grails 7 command classes link again. - Adapt legacy commands to the new contract via LegacyApplicationCommandAdapter / LegacyApplicationCommandAware, and discover them from the legacy META-INF/grails.factories key in ApplicationContextCommandRegistry. Each legacy command is instantiated in isolation so one faulty command cannot suppress the rest, and a new-contract command always wins a name clash. A one-time deprecation warning nudges authors to migrate. - Unwrap the adapter in GrailsApplicationContextCommandRunner so Spring autowiring and the skipBootstrap lookup target the real legacy command that is subsequently executed. - Register per-command Gradle tasks for legacy commands found on the runtime classpath, degrading gracefully when the classpath cannot be resolved at configuration time (the generic runCommand task always works). Separately, fix a Groovy 5 regression affecting create-script codegen scripts: a hyphenated script filename (for example audit-quickstart) produced a class name without the hyphen, so the command resolved under the wrong name. GroovyScriptCommandFactory now uses the filename-derived command name. Adds unit and integration tests (including exception-isolation and adapter/runner coverage), a real end-to-end functional example under grails-test-examples/legacy-commands that boots a Grails 8 application and runs a legacy plugin's ApplicationCommand, GrailsApplicationCommand and hyphenated script, and upgrade documentation describing the compatibility path and which command mechanisms are affected. Assisted-by: claude-code:claude-4.8-opus

Description
Grails commands (
ApplicationCommandimplementations) have always shipped inside runtime pluginartifacts, dragging CLI-only dependencies onto application runtime classpaths. This causes real
failures:
grails-shell-clileaks a conflicting Groovy onto the app classpath (see thelong-standing exclusion + TODO in
grails-data-hibernate{5,7}/dbmigration/build.gradle), and aCLI-only Spring Boot
WebApplicationInitializerbreaks classic WAR deployment with an NPE(#15377) unless users hand-filter the
bootWarclasspath.(no classifiers or capability syntax for consumers), fully consumable by Maven as well as Gradle.
Framework changes
grails-core-cli: the command contract moves fromgrails.dev.commands.*toorg.apache.grails.core.cli.*. Command registrations move fromMETA-INF/grails.factoriesto adedicated
META-INF/grails-cli.factories, written by a newCommandFactoriesTransformationthat ships in the cli artifact (so it is active exactly when a command can compile). The default
grails-corejar contains no command code and no command contract.Automatic-Module-Name: dbmigration (h5/h7, 29dbm-*commands each), the hibernate plugins(
schema-export), scaffolding (9generate-*commands), web-url-mappings(
url-mappings-report), spring-security, and spring-security-oauth2.grails-shell-cliis gonefrom every runtime dependency graph.
Build/tooling changes
org.apache.grails.gradle.grails-cliplugin (applied automatically by the Grailsapplication/plugin plugins): registers the
grailsCliconfiguration — compile-visible forgrails-app/commandssources and on the command-runner and test classpaths, but never on themain
runtimeClasspath, so commands and their CLI-only dependencies are excluded frombootRun/bootJar/bootWar. It auto-provisionsgrails-core-cli+grails-console, anddiscovers plugin companions automatically: a command-bearing plugin advertises its companion
through a
Grails-Cli-Artifactmanifest attribute on its runtime jar, and the plugin walks theresolved dependency graph (including transitive plugins) and adds each advertised companion to
grailsCli. Per-command Gradle tasks (dbmUpdate, …) register from the discovered companions —no
buildscript { classpath }entry needed. Opt out withgrails { cliAutoProvision = false }.The
console/shelltasks draw from the same provisioned tier, so generated apps no longerdeclare
console "org.apache.grails:grails-console".org.apache.grails.gradle.grails-plugin-cliplugin for plugin authors (dogfooded by theframework's own modules): one
applysets up the cli source set as a feature variant, thecommand contract on its compile classpath, the manifest advertisement, and the companion
publication.
Support additional source sets and custom publishing grails-gradle-publish#34 (requires
grails-publish≥1.0.0-SNAPSHOT; the version isbumped in
dependencies.gradle).Consumer impact
Most applications upgrade with no build changes: declaring a command-bearing plugin is enough,
and its commands (and Gradle tasks) follow automatically. Application commands in
grails-app/commandsonly need the import rename (grails.dev.commands.*→8.0.x— breaking changes are part of the major release).Code Quality
suites, dbmigration integration tests, the config-report end-to-end integration test
exercising the full discovery → factories → runner chain, forge feature specs, and
grails-gradle plugin tests).
./gradlew build --rerun-tasks.aggregateViolationsreports zeroCheckstyle/CodeNarc/PMD/SpotBugs findings).
beyond the approved scope.
Licensing and Attribution
Documentation
Gradle plugins catalog,
create-commandreference).-cliartifacts, automatic discovery, and the new plugins.grails-cli.factoriesclean break, the
grailsCliconfiguration, and the third-party plugin migration path.