I’ve been exploring Gradle’s plugin management and came across the following distinctions:
The
pluginManagement { plugins { } }
block in settings.gradle is used solely to configure plugin versions and resolution strategies. It doesn’t actually apply plugins—it merely centralizes the version information for plugins that will be applied later via the top-levelplugins { }
block in either settings.gradle or build scripts.In contrast, the top-level
plugins { }
block both resolves and applies plugins to the project.
I found documentation and discussions (a Stack Overflow reference) that recommend using a Version Catalog to centrally define plugin versions instead of relying on the pluginManagement { plugins { } }
block.
Official Kotlin documentation also recommands using Version Catalog.
My question is:
What are the concrete benefits of using a Version Catalog for plugin version management compared to using the pluginManagement { plugins { } }
block in settings.gradle?
Is it purely for centralization and dynamic version retrieval, or are there additional reasons (such as build performance, maintainability, or clarity) that make it the best practice?
Additionally, are there any official references or deeper technical explanations in the Gradle source or documentation that clarify this preference?
I’ve been exploring Gradle’s plugin management and came across the following distinctions:
The
pluginManagement { plugins { } }
block in settings.gradle is used solely to configure plugin versions and resolution strategies. It doesn’t actually apply plugins—it merely centralizes the version information for plugins that will be applied later via the top-levelplugins { }
block in either settings.gradle or build scripts.In contrast, the top-level
plugins { }
block both resolves and applies plugins to the project.
I found documentation and discussions (a Stack Overflow reference) that recommend using a Version Catalog to centrally define plugin versions instead of relying on the pluginManagement { plugins { } }
block.
Official Kotlin documentation also recommands using Version Catalog.
My question is:
What are the concrete benefits of using a Version Catalog for plugin version management compared to using the pluginManagement { plugins { } }
block in settings.gradle?
Is it purely for centralization and dynamic version retrieval, or are there additional reasons (such as build performance, maintainability, or clarity) that make it the best practice?
Additionally, are there any official references or deeper technical explanations in the Gradle source or documentation that clarify this preference?
Share Improve this question asked 18 hours ago satanmoosatanmoo 819 bronze badges 1- 1 Couple good answers here, I will add that the version catalog is defined in TOML which has a specification which one can create a library to parse. Compared to Groovy or Kotlin DSL, you need to either do some regex/parsing magic or parse into a AST and do some magic there. All of that to say, TOML is easier for tools such as Dependabot to parse and recommend updates. – Cisco Commented 10 hours ago
2 Answers
Reset to default 1Version catalogs
A version catalog is a centralised way of setting versions, library coordinates and plugin ids in a centralised, type-safe way since placing them there generates accessors for the values in all projects.
You could create similar features by writing code to do so in buildSrc
or your own plugin that was applied in relevant builds. However the version catalog does so using a standard API, which naturally offers advantages over every project implementing their own style of version catalog (and I remember my efforts to do so!).
Using constraints in the settings file
There are several issues with fixing plugin (and possibly library) versions in the settings file:
- This would require ids and artifact coordinates to be written as error-prone strings in the settings file and all build files where it was applied
- What if one of your projects needed to use a different version of a plugin to all the others? That might not be too easy to arrange
- This approach is also not as "declarative" as using the version catalog accessors in build file: it is preferable for each build file to set out specification of its build, not have aspects set mysteriously from other files. It's not as easy to quickly see why versions are set the way they are.
It simply doesn't achieve all the benefits of the version catalog.
It stems from the maven time. dependencies
and plugins
could be written without version
and other properties, when a single root project had a dependencyManagement
and/or pluginManagement
. The dependencies
inside dependencyManagement
were the only ones needing a version
, and those depencies actually were not working, served just as templates.
At the same time in maven there was an other practice defining version
name constants. This was motivated by related library jars often having the same version.
I am an old schooler, and I like using maven and ~Management. In a version
field I can press Ctrl+Space and get a list of current available possibly newer versions.
But one can understand having just one single clean methodology using version catalogs. And easily dealing with sibling libraries having the same version number.