Skip to content

Record the Forge feature pack of a plugin version in the plugin index - #326

Open
jdaugherty wants to merge 4 commits into
mainfrom
feat/forge-packs
Open

jdaugherty wants to merge 4 commits into
mainfrom
feat/forge-packs

Conversation

@jdaugherty

@jdaugherty jdaugherty commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

The Grails side of this is the work of apache/grails-core#16348 (one generator: Forge feature packs and the unified CLI, targeted at 10.0.x) and is not merged yet. This PR can be merged prior to that and sets a new format up so the new CLI will work with it.

It changes index-plugins.groovy and README.md, and adds index-plugins-test.groovy.

Why

Grails 10 lets a plugin ship a feature pack in its main jar (META-INF/grails-forge/feature.yml, packaged by the
grails-plugin Gradle plugin from src/main/forge). With it, grails create-app --features <name> can add the
plugin to a new application. To find which plugin and version has a feature of a given name, the CLI reads a
catalog, and the catalog it reads is this repository's grails-plugins-index.json, as it is: the top-level array of
plugins, with the version-level coords and maven-repo overrides, grailsVersion, deprecated and
artifactAvailable. The only thing the index lacks is a record of which versions have a pack.

What changes

For a version whose main jar contains META-INF/grails-forge/feature.yml, the indexer adds one property to that
version, in the YAML file and therefore in the index:

- version: 4.1.0
  date: 2026-11-20T10:00:00Z
  grailsVersion: 10.0.0 > *
  pack:
    format: 1
    kind: feature            # or preset
    name: my-feature         # the name given to --features
    templateApi: 1
    applicationTypes: [web]  # only when the descriptor declares them
    compatibility:
      grails: '[10.0.0,11.0.0)'
      forge: '[10.0.0,11.0.0)'
    sha256: 5f2c...          # of the jar as downloaded

Nothing else of the format changes. The index stays a top-level array; a consumer that does not know pack is not
affected (the plugin page ignores it).

  • The descriptor is read as data only: SnakeYAML SafeConstructor, no aliases, anchors or tags, at most
    256 KiB and 20 levels (the limits Grails itself applies). Nothing of the jar is executed.
  • Only the properties above are copied, each checked for its type and form. grailsVersion is not repeated in
    pack: the CLI uses the version's grailsVersion together with compatibility.grails, and a pack is offered
    only for a Grails that both allow.
  • sha256 is the SHA-256 of the jar the indexer downloaded anyway. The CLI refuses a jar with another digest, so
    the entry is tied to one jar. It must not be written or edited by hand.
  • A pack is only read from the main .jar, not from -plain.jar or a Grails 2 .zip.
  • The name of a pack belongs to the first plugin that is indexed with it. The CLI refuses a name that more than one
    plugin has until the plugin is named with it, so the pack of a release of another plugin with that name is not
    recorded, and the indexer logs a warning. A feature and a preset can have the same name.
  • One bad jar never fails the run: a descriptor that cannot be used is logged
    (WARNING: Ignoring the Forge feature pack of <url>: ...) and the version is indexed without pack, as today.
    A grails-plugin.xml that cannot be read is logged as well, and the version keeps its pack.
  • The jar is now downloaded once and read for both grailsVersion and the pack, and the temporary file is deleted
    after it is read instead of at JVM exit.
  • A version that is pack-only (no grails-plugin.xml in the main jar, -plain.jar or .zip) is still indexed when
    it has a pack; the CLI then goes by compatibility.grails alone.

Versions already in the YAML files

The indexer never updates a version that is already present, so existing versions would never get a pack, and a
pack written by hand would stay. A new flag makes pack what the jar has on request (added, or replaced or removed
with a warning) and changes nothing else of a version:

groovy index-plugins.groovy --rescan-packs                       # every plugin: one download per existing version
groovy index-plugins.groovy --rescan-packs grails-plugins/org/example/my-plugin.yml

It honours a version's own coords and maven-repo, and skips versions with artifactAvailable: false. Over the
whole index it is about 5,000 downloads, so it is meant to be run once, or for single files as plugins adopt packs.
The scheduled workflow is unchanged and does not pass the flag.

Trust

A pack entry makes a feature name resolve to that jar for every user who names this index as a catalog, and a
pack is code that runs when an application is generated. The review of a pull request that adds a plugin, or that
changes coords or maven-repo, therefore decides more than what the plugin page shows, and so does the review of
the scheduled "Update Plugin Index" pull request when it brings a new pack: the README says what to look at. The Grails CLI does not
read this index by default for that reason; a user has to name it.

What was run

With Groovy 4.0 and SnakeYAML 2.4 from the local Maven cache, against a Maven repository served on the loopback
interface (the script only speaks HTTP, so a file: repository cannot be used), with jars made of the pack of the
plugin-forge-pack test project of grails-core:

  • a plugin with a pack in two new versions and one version already in its YAML: the two new versions got pack
    with the jar's SHA-256 (checked against shasum); the existing one got it only with --rescan-packs;
  • jars whose descriptor uses an alias, uses a tag, has a name that is no feature name, or is larger than 256 KiB:
    each logged and indexed without pack, and the run went on; the next version of the same plugin got its pack;
  • a plugin without a pack: indexed as today.

The index that run wrote was read by the Grails CLI's catalog reader. Not run: the script against the real
repositories, the GitHub workflows, and --rescan-packs over the whole index.

When the main jar of a version contains META-INF/grails-forge/feature.yml, add a pack property to that version: the format, kind, name, template API, application types and compatibility ranges of the descriptor, read as data with bounds, and the SHA-256 of the jar. A jar whose descriptor cannot be used gets no pack and does not fail the run. Versions already indexed are looked at again only with --rescan-packs.
…r types

The indexer held the application types of a Forge feature pack to a list of four, while Grails 9 creates five kinds of application: rest-api-plugin was missing. A pack that declared [web, rest-api-plugin] was refused as a whole, so its version was indexed without a pack and the feature was not offered for web applications either. Since a version already indexed is not looked at again without --rescan-packs, the loss was permanent.

The list now has all five types. A name that has the form of a type but is not among them no longer costs the pack its entry: the types are recorded as the descriptor names them and a warning names the unknown one. The Grails command line passes over a type it does not know, so the pack stays offered for the types it is validly for, and a type a later Grails adds does not need a new indexer first. Only a value that cannot be a list of names of types is still refused, with the warning the indexer gives for every descriptor it cannot use.

A preset names the one type it is for in applicationType and has no applicationTypes, so the indexer recorded no type for it and the index offered every preset for every type. The type of a preset is now recorded as the one entry of applicationTypes, which is where the command line reads it, and a preset without a type gets no entry.

index-plugins-test.groovy tests what is recorded of a pack. It compiles the classes of the indexer without running it, so it reads no plugin file and downloads no plugin.

@sbglasius sbglasius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an AI assisted review

Re-reviewed 5e51ab5 (rest-api-plugin, unknown types kept with a warning, preset type recorded under applicationTypes, tests). LGTM.

Nits, non-blocking:

  • Error message "names in '$key' what cannot be the name..." reads oddly; "names in '$key' a value that cannot be..." perhaps.
  • Keeping unknown types means a typo like rest-apis lands in the index, with only a log line to show for it. Fine given the CLI skips unknown types, just noting it.

@matrei matrei left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good overall. Reading the descriptor as data only, with size and depth limits, and making sure a bad pack never fails the run are both good choices. A few things I noticed:

Feature-name collisions between plugins
pack.name is copied from the jar as it is (L441), and nothing checks whether another plugin already has a pack with that name. New versions arrive through the scheduled "Update Plugin Index" PR, not through the add-a-plugin review that the Trust section relies on. So any plugin that is already listed can ship a release with name: spring-security-core, and the index then has two plugins' packs under one feature name. Could the directory pass collect pack names per coords and warn about (or drop) a pack whose name another plugin already has? At a minimum, the README should ask maintainers to check pack.name in those automated PRs.

A related point: a hand-written pack in a plugin YAML is copied into the index without any check, and --rescan-packs skips versions that already have one. So nothing enforces "Do not write or edit pack by hand".

A broken grails-plugin.xml throws away a valid pack
readPluginArtifact reads the pack first and then calls readGrailsVersion (L567-568). If XmlSlurper throws (malformed XML, or a DOCTYPE, which the default XmlSlurper rejects), the pack is lost. With --rescan-packs this is only logged as "No Forge feature pack read", and in the normal run it aborts the whole run. If readGrailsVersion were wrapped in a try/catch that logs the error and returns null, the pack would be kept, and "one bad jar never fails the run" would also hold for the plugin descriptor.

Early break when the main jar has a pack but no grails-plugin.xml
if (grailsCompatibility || forgePack) break (L339) stops before -plain.jar and .zip are tried. Such a version gets pack but no grailsVersion, and the "Could not find plugin artifact" warning no longer fires. If pack-only versions are intended, what does the CLI do when grailsVersion is missing? Does it go by compatibility.grails alone? If not, it would be safer to break only on grailsCompatibility and still keep the pack from the main jar.

Unknown application types
applicationTypes: [batch-job] is recorded with only a warning (L517). If the CLI skips types it doesn't know, that list becomes empty. Does the CLI treat an empty list like a missing key, meaning "every type"? If it does, that pack would be offered for every application type. It may be worth refusing a pack whose types are all unknown.

Minor:

  • readForgePack also runs for -plain.jar and the .zip. It hashes the file and logs warnings about a pack that is then thrown away. A flag on readPluginArtifact so that the pack is only read for the main jar would avoid this.
  • --rescan-packs downloads a second time any version that was added earlier in the same run without a pack. Every later rescan also downloads every pack-less version again (about 5,000 jars).
  • extractGrailsVersionFromPluginJar is no longer called, and its Javadoc belongs on readGrailsVersion, whose body is also indented four spaces too far.

The Grails change this goes with, apache/grails-core#17114, now targets
10.0.x, so the examples and the tests use the range of the Grails 10 line.
…scriptor

- The name of a pack belongs to the first plugin that is indexed with it: the
  pack of another plugin with that name is not recorded, with a warning, and two
  plugins that have one name in their files already are reported.
- A grails-plugin.xml that cannot be read no longer costs the jar its pack, nor
  fails the run.
- A main jar with a pack and no plugin descriptor no longer ends the search for
  the grailsVersion in the other artifacts, and a pack is not read at all from
  the plain jar or the zip.
- --rescan-packs replaces or removes a pack that is not what the jar has, and
  does not download again a version the same run added.
- extractGrailsVersionFromPluginJar, which nothing called, is removed.

@jdaugherty jdaugherty left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matrei thanks for the review. c5d9f63 answers it; the CLI behaviour named below is that of apache/grails-core#17114 (PackCatalog / PackCatalogs in grails-forge-cli).

Feature-name collisions between plugins. The CLI does not pick one of two plugins: when more than one plugin of the catalog has a pack of the name that is usable for the application, it refuses the name ("More than one plugin of the feature catalog has a feature X: name the one that is meant as group:artifact#X or ..."). So a second spring-security-core could not take the name over, but it could take it away from everyone who writes the bare name. The indexer now keeps a name with the first plugin that is indexed with it: before any file is processed it reads the names the plugin files already have, and the pack of a new release of another plugin with such a name is not recorded, with a warning (Ignoring the Forge feature pack of <coords>:<version>: its name ... is that of a pack of <holder>). Two plugins that have one name in their files already are both kept and reported. A feature and a preset can share a name, as the CLI selects them apart. The README has a new section for maintainers that asks to look at each new pack.name in the "Update Plugin Index" pull request, and says how a name is handed over.

A hand-written pack. --rescan-packs now also reads the versions that have a pack, and replaces or removes one that is not what the indexer records of the jar, with a warning; a version whose jar cannot be read is left as it is. The scheduled run does not do this, as it would download every jar with a pack on every run, so the README asks maintainers not to accept such a change and to run --rescan-packs <file> on it. On the side of the CLI a hand-written entry is held to its sha256: a jar with another digest is refused.

A broken grails-plugin.xml. Fixed as you suggest: the descriptor is read in its own try/catch, logged (WARNING: Ignoring the plugin descriptor of <url>: ...) and the version is recorded with its pack and without grailsVersion. That also ends the normal run failing on such a jar.

Early break. The loop now breaks on grailsVersion only, so a main jar with a pack and no plugin descriptor still gets its grailsVersion from -plain.jar or the .zip. Pack-only versions are intended: when a version has no grailsVersion the CLI goes by compatibility.grails alone, and when it has one, both ranges have to allow the Grails version. Such a version is now logged (No grailsVersion found for <coords>:<version>, which is recorded with its Forge feature pack alone).

Unknown application types. Not changed. The CLI does not drop the types it does not know: it keeps the list as it is and offers the pack only for an application whose type is in it, so [batch-job] is offered for no type, not for every type. Only a missing applicationTypes means every type, and an empty list is refused by both the indexer and the CLI. Refusing a pack whose types are all unknown here would cost a pack of a later Grails with a new type its entry until this script learns the type.

Minor:

  • The pack is now read for the main jar only (readPluginArtifact(url, withPack)); nothing of -plain.jar or the .zip is hashed or reported.
  • --rescan-packs no longer downloads again a version the same run added. That a full rescan downloads every version each time is unchanged: it is meant to be run once over the index and after that for single files.
  • extractGrailsVersionFromPluginJar is removed, its Javadoc is on readGrailsVersion, and the indentation is fixed.

@sbglasius the message now reads "names in '$key' a value that cannot be the name of a type of application". On the typo: agreed, it stays a log line, since the CLI offers the pack for the types it knows and for no other.

Tests: index-plugins-test.groovy now also runs the indexer against a Maven repository on the loopback interface, with a case for each point above (19 tests, all passing with Groovy 5.1.2).

@jdaugherty
jdaugherty requested a review from matrei December 4, 2026 13:02

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants