allegro / allegro/allwrite

Add plugin-aware gating to `AddTomlVersionCatalogPlugin`

Abierto
#178 0 comentarios 0 reacciones 1 asignado Reclamado por @PawelBalcerek Ver en GitHub
Lenguaje dominante
Kotlin
Estrellas
9
Forks
1
Merge medio
1 d 3 h
PR fusionados (30 d)
19

Descripción

### 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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.