allegro / allegro/allwrite

Add plugin-aware gating to `AddTomlVersionCatalogPlugin`

Aberta
#178 0 comentários 0 reações 1 responsável Reivindicada por @PawelBalcerek Ver no GitHub
Linguagem predominante
Kotlin
Estrelas
9
Forks
1
Merge médio
1d 3h
PRs com merge (30d)
19

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.