jdaugherty opened a new pull request, #16416:
URL: https://github.com/apache/grails-core/pull/16416

   ## Problem
   
   `GrailsGradlePlugin.applyGrailsBom()` added the selected Grails BOM as a 
`platform()` to every declarable configuration eagerly, from `afterEvaluate`. A 
platform is a declared dependency, and Gradle's `defaultDependencies { }` hooks 
only fire on a configuration that holds no dependencies at all 
(gradle/gradle#11209). Any configuration another plugin populates on demand 
therefore ended up holding only the BOM:
   
   - the core `jacoco` plugin's `jacocoAgent` / `jacocoAnt` never received 
`org.jacoco:org.jacoco.agent` / `org.jacoco:org.jacoco.ant`, so `./gradlew 
test` failed with `Expected configuration ':jacocoAgent' to contain exactly one 
file, however, it contains no files.`
   - the plugin's own `profile` configuration lost its default 
`org.apache.grails.profiles:<profile>` dependency the same way (visible in the 
new fixture when run against the unfixed plugin: 
`PROFILE_DEFAULT_DECLARED=false`).
   
   ## Fix
   
   The platform is now contributed through `Configuration.withDependencies` 
instead of `DependencyHandler.add`. Gradle runs a configuration's dependency 
actions once, when its dependencies are first observed (resolution, 
publication, `incoming.dependencies`): `defaultDependencies` first, and only 
while the configuration is empty, then `withDependencies`. The defaults other 
plugins install therefore keep firing, and the BOM still lands on every 
declarable configuration - including ones created after `afterEvaluate`, since 
the registration goes through `configurations.configureEach`. Published 
POMs/module metadata are unaffected: Gradle's publishing component reads 
`incoming.dependencies`, which runs the actions.
   
   Two places read declared dependencies eagerly in `afterEvaluate` and needed 
adapting:
   
   - `bom-property-overrides` auto-detects BOMs by scanning declared platforms. 
`applyGrailsBom` now registers the auto-applied BOM with the 
`bomPropertyOverrides` extension explicitly (respecting `autoDetect = false`), 
so property overrides keep working for the injected BOM.
   - `validateMicronautBom` accepted only a hand-declared `enforcedPlatform` on 
`implementation`. It now also accepts the case where `implementation` declares 
no Grails BOM by hand and the BOM selected for automatic application is a 
Micronaut variant (always contributed as `enforcedPlatform`).
   
   The effective-BOM selection (hand-declared BOM wins over `grails.bom`, fail 
fast on more than one) moved into a shared `effectiveGrailsBom()` helper used 
by both callers.
   
   ## Tests
   
   `grails-gradle/plugins` TestKit coverage:
   
   - New `bom-platform-default-dependencies` fixture (POM-only local 
repository, nothing hits the network): a Grails app applying `jacoco`, a custom 
configuration populated through `defaultDependencies`, and a version-less 
dependency managed by the BOM. Asserts `jacocoAgent`, `jacocoAnt`, the custom 
configuration and the `profile` configuration all keep their defaults *and* 
receive the platform, and that the lazily contributed platform still manages 
versions. Fails against the unfixed plugin.
   - New `bom-platform-micronaut` fixture: the auto-applied Micronaut variant 
satisfies the `enforcedPlatform` validation and arrives as `enforced-platform`; 
opting out without declaring one by hand still fails the validation.
   - Existing `bom-platform-basic` / `bom-platform-manual` / 
`auto-apply-bom-disabled` fixtures now observe dependencies through resolvable 
configurations (`incoming.dependencies`), and the basic one asserts the 
platform is not declared before observation.
   
   Docs: `gradleDependencies.adoc` and the Grails 8 upgrade notes describe the 
lazy contribution and its effect on `defaultDependencies`-populated 
configurations.
   
   ## Verification
   
   - `cd grails-gradle && ./gradlew :grails-gradle-plugins:codeStyle` - clean.
   - `cd grails-gradle && DO_NOT_CACHE_TESTS=1 ./gradlew 
:grails-gradle-plugins:test` - 44 suites, 308 tests, 0 failures. The new 
default-dependencies feature fails against the unfixed plugin 
(`JACOCO_AGENT_RESOLVED=[org.apache.grails:lazy-bom:1.0-lazy]`, 
`PROFILE_DEFAULT_DECLARED=false`).
   - `./gradlew rat` from the root - 0 unknown licenses.
   - Root build smoke check against the composite-included plugin: `jacoco` 
applied to `grails-test-examples/app1` with `grails { bom = 'grails-bom' }` 
forced on (the test examples normally opt out). 
`:grails-test-examples-app1:dependencies --configuration jacocoAgent` now lists 
`org.jacoco:org.jacoco.agent:0.8.14` next to `org.apache.grails:grails-bom -> 
project ':grails-bom'`, and the `profile` configuration declares 
`org.apache.grails.profiles:web` next to the BOM.
   
   Fixes #16335
   


-- 
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]

Reply via email to