allegro / allegro/allwrite

Add plugin-aware gating to `AddTomlVersionCatalogPlugin`

Aperta
#178 0 commenti 0 reazioni 1 assegnatario Rivendicata da @PawelBalcerek Vedi su GitHub
Lingua principale
Kotlin
Stelle
9
Fork
1
Merge medio
1g 3h
PR unite (30g)
19

Descrizione

### Context:

`AddTomlVersionCatalogPlugin` currently adds the configured plugin alias to every applicable Gradle build file and updates the shared version catalog without knowing whether a target plugin (e.g. `application` or `library`) is applied. This prevents the recipe from being safely scoped to selected modules in multi-module builds.

OpenRewrite's existing plugin-detection recipes are not suitable here: `FindPlugins` misses Kotlin DSL bare plugin accessors such as `plugins { application }`, while `ModuleHasPlugin` and its fallback rely on Gradle project markers that allwrite does not produce.

### Proposed solution:

1. Add an internal, reusable `AppliedPluginDetector` in `allwrite-recipes` that determines whether a given plugin is applied in a Gradle build file.
2. Support Kotlin DSL bare and backticked accessors, Kotlin and Groovy `id(...)` declarations, and Kotlin and Groovy `apply` declarations.
3. Restrict detection to build files and avoid false positives for extension blocks, similarly prefixed plugin IDs, and unrelated identifiers.
4. Extend `AddTomlVersionCatalogPlugin` with an optional `onlyIfPluginApplied` plugin ID parameter, defaulting to `null` to preserve existing behavior.
5. When the option is configured, collect the paths of matching build files during scanning, add the plugin alias only to those files, and update the version catalog only when at least one matching file exists.
6. Ensure gated execution never creates a missing `plugins {}` block.
7. Add detector tests and regression coverage for ungated behavior, Kotlin and Groovy syntax, single- and multi-module builds, multiple matching modules, non-matching modules, and files without a `plugins {}` block.
8. Update the recipe documentation with the new option and example, and add `AppliedPluginDetector.kt` to the relevant `AGENTS.md` directory structure.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.