依赖版本目录与平台
使用版本目录和 Gradle 平台(BOM)集中管理大型多模块构建中的依赖版本,并强制保持一致性和规范性。
依赖版本目录与平台 是 CoddyKit 上的免费 Groovy & Gradle: JVM Automation and Build Engineering 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Groovy & Gradle: JVM Automation and Build Engineering 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Groovy & Gradle: JVM Automation and Build Engineering 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
The Version Drift Problem
In enterprise builds with dozens of modules, the same library can end up declared with different versions, causing subtle runtime conflicts. Centralizing versions prevents this drift.
What is a Version Catalog?
A version catalog is a single typesafe list of dependencies and versions, defined in gradle/libs.versions.toml and shared across all modules.
The TOML Format
The catalog has sections for versions, libraries, and plugins.
[versions]
guava = "33.0.0-jre"
[libraries]
guava = { module = "com.google.guava:guava", version.ref = "guava" }Using Catalog Entries
In a build script you reference the typesafe accessor, getting IDE completion and a compile error if the name is wrong.
dependencies {
implementation(libs.guava)
}Bundles
Group related libraries into a bundle so modules add them all at once.
[bundles]
networking = ["retrofit", "okhttp"]Plugin Versions in the Catalog
Catalogs can also pin plugin versions, keeping the whole toolchain consistent.
[plugins]
spring = { id = "org.springframework.boot", version = "3.2.0" }What is a Platform?
A platform (Maven BOM) constrains versions of transitive dependencies without adding them. It governs what version wins during resolution.
Applying a Platform
Import a BOM with the platform() notation; aligned dependencies inherit its managed versions.
dependencies {
implementation(platform("org.springframework.boot:spring-boot-dependencies:3.2.0"))
implementation("org.springframework:spring-web")
}Publishing Your Own Platform
Large orgs publish an internal platform module so every team aligns on approved versions automatically.
plugins { id("java-platform") }
dependencies {
constraints {
api("com.acme:logging:2.1.0")
}
}Catalog vs Platform
They complement each other:
- Catalog: what you type when declaring dependencies
- Platform: which transitive versions are allowed at resolution
Governance Benefits
Together they give central teams control: upgrade a library once, and every module follows, with reviewable changes in version control.
Quick Check
Test your understanding of catalogs and platforms.
Recap
You learned centralized version management:
- Catalog in
libs.versions.tomlgives typesafe accessors - Bundles group related libraries
- Platforms (BOMs) constrain transitive versions
- Together they enforce consistency across large builds
常见问题解答
「依赖版本目录与平台」课时是免费的吗?
是的 — 「依赖版本目录与平台」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Groovy & Gradle: JVM Automation and Build Engineering 课程的其余内容,请升级到 CoddyKit PRO。 Groovy & Gradle: JVM Automation and Build Engineering 课程共包含 4 节课。
「依赖版本目录与平台」这节课中我会学到什么?
使用版本目录和 Gradle 平台(BOM)集中管理大型多模块构建中的依赖版本,并强制保持一致性和规范性。 你通过在浏览器中直接运行的动手代码来练习 Groovy & Gradle: JVM Automation and Build Engineering,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Groovy & Gradle: JVM Automation and Build Engineering 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Groovy & Gradle: JVM Automation and Build Engineering 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「依赖版本目录与平台」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Groovy & Gradle: JVM Automation and Build Engineering 课中编写并运行代码吗?
能。每节 Groovy & Gradle: JVM Automation and Build Engineering 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- Gradle 构建扫描与洞察
- 安全与凭据管理
- 约定插件与构建逻辑
- 依赖版本目录与平台