# Apply plugin with version catalog

**URL:** <https://discuss.gradle.org/t/apply-plugin-with-version-catalog/43029>\
**Category:** Help/Discuss\
**Created:** [May 31, 2022, 7:45am UTC](https://discuss.gradle.org/t/apply-plugin-with-version-catalog/43029 "2022-05-31T07:45:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BigMichi1](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bigmichi1/32/9069_2.png) [@BigMichi1](https://discuss.gradle.org/u/BigMichi1)\
**Post date:** [May 31, 2022, 7:45am UTC](https://discuss.gradle.org/t/apply-plugin-with-version-catalog/43029/1 "2022-05-31T07:45:49Z")

</div>

when I use a version catalog to define plugins what would be the correct way to apply the plugin to all subprojects?

currently, it looks like this:  
**libs.versions.toml**

```gradle
[version]
gradle-plugin-forbiddenapis = "3.3"

[plugins]
forbiddenapis = { id = "de.thetaphi.forbiddenapis", version.ref = "gradle-plugin-forbiddenapis" }

```

**build.gradle**

```gradle
plugins {
    alias(libs.plugins.forbiddenapis) apply false
}

ext {
    subprojectsWithoutPlatform = subprojects.findAll {
        it.name != 'platform' && new File(it.projectDir, "build.gradle").exists()
    }
}

configure(subprojectsWithoutPlatform) {
    apply plugin: libs.plugins.forbiddenapis.get().pluginId
    forbiddenApis {
        ignoreFailures = false
    }
}

```

so the question is related to `apply plugin: libs.plugins.forbiddenapis.get().pluginId`, is this the way it should be done or should it be done differently.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [May 31, 2022, 9:27am UTC](https://discuss.gradle.org/t/apply-plugin-with-version-catalog/43029/2 "2022-05-31T09:27:27Z")

</div>

Actually practically any `subprojects { ... }`, `allprojects { ... }`, `project(...) { ... }`, `configure(listOfProjects) { ... }` and similar should be avoided due to various reasons, reaching from being non-idiomatic in current Gradle, over hindering more advanced features like parallel execution or configuration cache by introducing coupling between projects, to decreasing build maintainability.

The way to go is to have convention plugins where you define the common logic and then apply these convention plugins in the concrete build script where you want it to be applied.
