What Is New in Gradle 5
Gradle 5 introduces a major evolution focused on faster builds, better dependency management, and enhanced developer productivity. The release is packed with features that streamline the development workflow across JVM, native, and web projects.
| Category | Key Highlights |
|---|---|
| New Features | Kotlin DSL 1.0, Gradle Build Init improvements, Java 11 support, Task timeouts |
| Performance | Incremental annotation processing, Build Cache for Kotlin DSL, Gradle Module Metadata |
| Dependency Management | Version ranges in Substitutions, Platform dependencies, Strict version constraints |
| Improvements & Updates | Searchable documentation, Gradle Wrapper --gradle-version arg, Updated plugins |
| Deprecated & Breaking Changes | Removal of legacy features (e.g., `compile` configuration), Changes to tooling API |
How does Gradle 5 speed up my build?
Gradle 5 tackles build speed from multiple angles. The introduction of incremental annotation processing for Java means recompilations are faster when only annotation-generated code changes.
Build Cache support is now extended to Kotlin DSL script files. Caching the compiled build logic itself can shave off significant time in CI environments where the build script doesn't change often.
Gradle Module Metadata
This new, rich metadata format allows Gradle to make smarter dependency resolution decisions. It can avoid downloading unnecessary artifact variants, which cuts down network and disk I/O during dependency resolution.
What dependency management improvements should I use?
Dependency management gets more powerful and declarative. You can now define platform dependencies to manage consistent versions across a set of modules, similar to Maven's BOM.
Strict version constraints give you fine-grained control. You can declare a preferred version but enforce strict limits, preventing unwanted upgrades or downgrades.
dependencies {
implementation('com.google.guava:guava:27.0.1-jre')
constraints {
implementation('com.google.guava:guava') {
version {
strictly('[27.0.1, 28.0.0[')
prefer('27.0.1')
}
}
}
}
Version ranges are now supported within dependency substitution rules, providing more flexibility when aligning or replacing dependencies in complex projects.
Is the Kotlin DSL ready for production?
Yes, Kotlin DSL 1.0 is a headline feature, marking it stable for production use. It offers improved editing experience with better IDE support, including content assist and navigation in IntelliJ IDEA and Android Studio.
The syntax is more concise and type-safe compared to Groovy. In practice, this means fewer runtime errors in your build scripts and easier refactoring.
plugins {
java
application
}
application {
mainClassName = "com.gradle.sample.App"
}
Build Cache for Kotlin DSL scripts also improves performance, making the switch more practical for larger builds.
What breaking changes will affect my upgrade?
The most common impact is the final removal of the legacy compile and runtime configurations. You must migrate to implementation, api, runtimeOnly, and compileOnly.
Several deprecated properties and methods in the Tooling API have been removed. If you have custom tooling or IDE integrations, check the compatibility.
The --recompile-scripts option is gone. Use the --rerun-tasks option or clean your project if you need full re-execution.
What new tools help with project creation?
The gradle init command is significantly smarter. It can generate new projects with Kotlin DSL build scripts by default and offers more interactive options.
For library authors, init now supports generating multi-project builds with a Java library and a companion test suite project. This sets up a modern, reusable project structure out of the box.
You can specify the Gradle version directly when using the Wrapper: gradle wrapper --gradle-version=5.0. This simplifies automation scripts for setting up new projects.
FAQ
How do I enable incremental annotation processing?
You need to explicitly opt-in for each annotation processor in your build. Set the gradle.processing system property or use the new CompileOptions in your Java plugin configuration to enable it.
Can I use Java 11 with Gradle 5?
Yes, Gradle 5 runs on and supports building with Java 11. Your build scripts and tasks can leverage new Java APIs. Ensure your IDE and any other tooling in your pipeline are also compatible.
What happens if I don't migrate from 'compile' configuration?
The build will fail. Gradle 5 removes the old configurations entirely. You must update your build scripts to use the implementation and api configurations introduced in Gradle 3.4.
How does the new task timeout feature work?
You can set a timeout duration on any task. If the task runs longer than specified, Gradle will interrupt it. This is useful for preventing CI hangs from runaway tasks, like integration tests.
Where can I find the new searchable documentation?
The Gradle User Manual and DSL reference are now searchable directly on the documentation website. This makes it much faster to find specific configuration options or guidance without browsing through pages.