Securing Gradle Builds
Every Gradle build pulls in code from external repositories, executes tools you didn’t author, and publishes artifacts that others will trust. Each step is a potential attack surface.
For a typical Gradle build, the supply chain has three layers:
-
Repositories: where artifacts are stored and served.
-
Dependencies: the libraries and plugins your project consumes.
-
Build Tool: Gradle itself, including the Wrapper, init scripts, and everything under
~/.gradle.
Attacks can originate at any layer and then propagate downstream through published artifacts, transitive dependencies, or compromised tools. Even the build tool itself is an attack vector.
Gradle provides features to protect each layer:
| Layer | Common issues and attacks | How to protect it |
|---|---|---|
Repositories |
|
Centralize repository declarations, require HTTPS, restrict which coordinates each repository is allowed to serve, and mark internal artifacts as exclusive to internal repositories. |
Dependencies |
|
Screen for known vulnerabilities, verify artifact checksums to protect integrity, and verify PGP signatures to protect provenance. |
Build Tool |
|
Pin and verify the Gradle Wrapper and distribution, protect the Gradle User Home, guard init scripts and |