百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

gradle-project-setup-howto

> 包管理
开源

如何使用智能依赖管理来构建一个不断增长的 Gradle 项目?

198 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

如何使用智能依赖管理来构建一个不断增长的 Gradle 项目?

How to set up a larger Gradle project

This repo contains a Gradle project structure with:

  • Centralized and maintainable build configuration and custom build logic
  • No dependency hell through smart dependency management with dependency rules and analysis

The main branch contains everything for a traditional Java project. The structure though, is good for any kind of project you may build with Gradle (Kotlin, Groovy, Scala, ...).

[!NOTE] There are adjustments on other branches of this repo that show how the setup can be varied:

  • Java Module System
  • Versions in BOM/Platform
  • Kotlin
  • Android
  • Java and Spring Boot

[!TIP] There are two sister repositories that share the same example with a different focus in the build setup

  • idiomatic-gradle Focus on structuring builds for both mono-repo or multi-repo setups
  • ️ javarcade Focus on structured dependency management with the JavaRCA recipe

Project Overview

Folder structure

…
  • Video: The Settings File

The $product-name/$module-name/build.gradle.kts files

Select a Component Type by using the corresponding convention plugin and define the dependencies of the module. For example:

plugins {
    id("org.example.gradle.component.library") // This is a 'library'
    id("org.example.gradle.feature.publish")   // Build feature only in this 'library' Module
}

dependencies {
    api(projects.coruscant)     // Depends on another Module of our project
    implementation(libs.guava)  // Depends on a 3rd party Module
}
  • Video: The Build Files
  • Video: Declaring Dependencies

The Convention Plugins

  • Video: (Convention) Plugins

Convention plugins are used to configure each aspect of the build centrally. To keep it structured, we put them into four categories: Base, Feature, Check, Report. Below you find all plugins listed. For more details, inspect the corresponding plugin files. Understanding Gradle videos that cover related topics are linked below each plugin file.

Base Plugins

Base plugins need to be used in all Modules to establish a certain foundation for the setup. For example, the same dependency management configuration should be applied everywhere to consistently use the same 3rd party libraries everywhere.

  • org.example.gradle.base.identity.gradle.kts
  • org.example.gradle.base.lifecycle.gradle.kts
    • Video: Lifecycle Tasks
  • org.example.gradle.base.lifecycle.root.gradle.kts
  • org.example.gradle.base.dependency-rules.gradle.kts
    • Video: Dependency Version Conflicts + Consistent Resolution
    • Video: Capability Conflicts + Component Metadata Rules

Feature Plugins

Each feature plugin configures one aspect of building the software – like compiling code or testing code.

  • org.example.gradle.feature.repositories.settings.gradle.kts
  • org.example.gradle.feature.project-structure.settings.gradle.kts
    • Video: Settings Plugins
  • org.example.gradle.feature.compile-java.gradle.kts
    • Video: Source Sets
    • Video: The JavaCompile Task
  • org.example.gradle.feature.javadoc.gradle.kts
  • org.example.gradle.feature.test.gradle.kts
    • Video: Configuring Testing
    • Video: The Test Task
  • org.example.gradle.feature.test-end-to-end.gradle.kts
    • Video: Feature Variants
  • org.example.gradle.feature.test-fixtures.gradle.kts
    • Video: Test Fixtures
  • org.example.gradle.feature.checksum.gradle.kts
    • Video: Configuring Task Inputs and Outputs
    • Video: Implementing Tasks and Extensions
  • org.example.gradle.feature.publish.gradle.kts
    • Video: Publishing Libraries
  • org.example.gradle.feature.use-all-catalog-versions.gradle.kts
    • Video: Centralizing Dependency Versions
  • org.example.gradle.feature.build-cache.settings.gradle.kts
    • Video: Caching

Report Plugins

Report plugins add reporting functionality to discover potential issues with the software or the build setup. They may generate data that is picked up and displayed by external tools like Develocity or Dependency Track. More reporting tools may be integrated in this category. Report plugins are not necessarily needed to build a working software.

  • org.example.gradle.report.code-coverage.gradle.kts
    • Video: Aggregating Custom Artifacts
    • Video: Test and Code Coverage Reporting
  • org.example.gradle.report.plugin-analysis.gradle.kts
  • org.example.gradle.report.sbom.gradle.kts
  • org.example.gradle.report.develocity.settings.gradle.kts

Check Plugins

Check plugins help with keeping the software maintainable over time. They check things like the dependency setup or code formatting. More style checkers or static code analysis tools could be added in this category. Check plugins are not necessarily needed to build a working software.

  • org.example.gradle.check.dependencies.gradle.kts
    • Video: Dependency Analysis
    • Video: Detect and Resolve Collisions on a Classpath
  • org.example.gradle.check.format-gradle.gradle.kts
  • org.example.gradle.check.format-gradle.root.gradle.kts
  • org.example.gradle.check.format-java.gradle.kts

Component Plugins

Component plugins combine plugins from all categories above to define Component Types that are then used in the build.gradle.kts files of the individual Modules of our software.

  • org.example.gradle.component.application.gradle.kts
  • org.example.gradle.component.library.gradle.kts

Testing Plugins

The Gradle TestKit can be used to test plugins. This can be helpful to enforce a certain structure, e.g. by testing if each plugin works on its own. And if you add custom tasks and advanced logic, you can add tests for that. As example, this project contains one test class: ConventionPluginTest.kt

There is also a help task that you can use to get a diagram of the convention plugins defined in the project:

./gradlew :aggregation:analysePluginApplicationOrder

The task generates a PlantUML file that you can render, for example, with the PlantUML IntelliJ plugin.

Continuously build and report using GitHub Actions and Renovate

  • build.yaml Configure GitHub to run builds and produce reports (inspect). Integrates with:
    • Develocity Build Scans (inspect)
    • Gradle Remote Build Cache
    • Reposilite (inspect)
    • Dependency Track
  • renovate.json Configure Renovate to automatically get version updates (inspect)

Notes

  • If you have a question, please ask in an issue.
  • The concrete things done in all places (custom tasks, components used in dependencies, additional plugins applied, etc.) are just examples. If you, for example, need to use addit

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javaandroidexamplesgradlejava

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类包管理
定价开源

> 相关工具

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image