codeconsole opened a new pull request, #15970: URL: https://github.com/apache/grails-core/pull/15970
Every Grails 8 application startup registers and loads the `domainClass` plugin twice (visible in M2, M3, and current SNAPSHOTs): ``` INFO ... g.plugins.DefaultGrailsPluginManager : Grails plug-in [domainClass] with version [8.0.0-M3] loaded successfully ... INFO ... g.plugins.DefaultGrailsPluginManager : Grails plug-in [domainClass] with version [8.0.0-M3] loaded successfully ``` ### Root cause `org.grails.plugins.domain.DomainClassGrailsPlugin` is declared by **two** `META-INF/grails-plugin.xml` descriptors on every application classpath: 1. `grails-core.jar` — the hand-written descriptor declares `CoreGrailsPlugin` **and** `DomainClassGrailsPlugin`. This is a leftover from Grails 2.x, when the class still lived in grails-core; the class later moved to the `grails-domain-class` module but the entry was never removed. 2. `grails-domain-class.jar` — carries its own build-generated descriptor declaring the same class. `ClasspathPluginFinder` creates one `PluginInfo` per *(descriptor, class)* pair and `DefaultPluginDiscovery.registerPlugin()` had no already-registered check, so both entries flow into the load order: the plugin is sorted, instantiated, and logged twice, with the second `plugins.put` silently overwriting the first instance. ### Fix - Remove the stale `DomainClassGrailsPlugin` entry from grails-core's hand-written descriptor. This is safe: the generated descriptor is packaged inside the `grails-domain-class` jar, so the class and its descriptor always travel together — the stale entry could only ever produce a duplicate (jar present) or a class-not-found skip (jar absent). - Defensively, `registerPlugin()` now skips a plugin whose name is already registered and logs a WARN including both versions, so a plugin accidentally declared by multiple descriptors can never double-load: ``` WARN ... Grails plug-in [domainClass] with version [8.0.0-M3] is already registered; skipping duplicate declaration with version [8.0.0-M3] ``` ### Tests Two new `PluginDiscoverySpec` features, exercised through public APIs only: - the same plugin class declared in two classpath `grails-plugin.xml` descriptors (reproducing the actual bug via the thread-context class loader) registers exactly once - the same plugin class supplied twice registers exactly once and the skipped duplicate is reported at WARN Both tests were verified to fail against the previous code. Note: the duplicate `domainClass` line is also visible in the startup output shown in #15969; the two PRs are independent and merge cleanly in either order (verified with `git merge-tree`). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
