allegro / allegro/allwrite

Add plugin-aware gating to `AddTomlVersionCatalogPlugin`

Ouverte
#178 0 commentaires 0 réactions 1 personne assignée Réclamée par @PawelBalcerek Voir sur GitHub
Langage dominant
Kotlin
Étoiles
9
Forks
1
Merge moyen
1 j 3 h
PR mergées (30 j)
19

Description

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

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.