What Is New in Gradle 2
Gradle 2 delivers significant performance gains, new dependency management features, and a more robust build daemon. This release focuses on making large project builds faster and more reliable.
| Category | Key Changes |
|---|---|
| Performance | Faster up-to-date checks, incremental Java compilation, improved build daemon. |
| Dependency Management | Component metadata rules, forced versions, Maven snapshot handling. |
| Build Daemon | Enabled by default, reduced startup overhead, improved stability. |
| Software Model (Incubating) | New DSL for defining custom build models and native binaries. |
| Usability & Fixes | Improved error messages, plugin enhancements, various bug fixes. |
How does Gradle 2 make my builds faster?
The biggest speed boost comes from incremental Java compilation. Gradle now only recompiles source files that changed or are affected by changes, not entire source trees. In practice, this can cut compilation time for small changes dramatically.
Up-to-date checks for tasks are also faster. Gradle optimizes how it checks if inputs and outputs have been modified. The build daemon is now on by default, which eliminates JVM startup costs for subsequent builds, making the command-line experience feel snappier.
What's new for managing library dependencies?
You can now write rules to manipulate component metadata directly in your build script. This lets you fix broken metadata from repositories or define variant-specific details without waiting for module publishers.
Forcing a specific version of a transitive dependency is simpler with the force attribute on a dependency declaration. Gradle also improves its handling of Maven snapshots, making it more reliable to fetch the latest -SNAPSHOT artifact during development.
Is the build daemon ready for production use?
Yes, the daemon is now stable and enabled by default. Earlier versions had it as an opt-in feature. This matters because it keeps a JVM instance warm between builds, caching project structure and task graphs. The result is much faster build startup times.
Stability and memory consumption have been improved. You can control it with the --daemon and --no-daemon flags, or configure it via org.gradle.daemon in your gradle.properties file.
What is the new Software Model for?
The Software Model is an incubating feature that provides a new, structured way to define builds beyond traditional tasks and source sets. It's particularly aimed at complex builds with multiple native binaries or custom build types.
It introduces a DSL for declaring components, binaries, and sources. While powerful, it's separate from the standard Gradle build script model. Most Java projects won't need it immediately, but it lays the groundwork for advanced native and polyglot builds.
FAQ
Should I upgrade to Gradle 2 immediately?
If your project uses standard Java, Android, or Groovy plugins, upgrading is straightforward and recommended for the performance benefits. Test your build with --dry-run or on a CI branch first to catch any plugin compatibility issues.
Does incremental compilation work with annotation processors?
It does, but with a caveat. If your annotation processor generates API code that other source files depend on, you may need to declare that relationship manually. Gradle's default heuristics might not detect it, requiring a full recompile.
How do I force a dependency version now?
You can use the force property on a dependency declaration. For example: compile('org.example:library:1.0') { force = true }. This is cleaner than the old dependency resolution strategy block for this specific use case.
Why is my build failing with a "Could not resolve all dependencies" error?
Gradle 2 tightened the consistency of dependency resolution, especially for dynamic versions. If you use ranges like 1.+, ensure your repository metadata is correct. Also, check that forced versions aren't creating conflicts with transitive dependencies.
Are any plugins broken in Gradle 2?
Plugins that rely on internal Gradle APIs might break. The most common issue is with plugins accessing the project.convention object. Check your plugin vendors for updates. The new component metadata rules often provide a better alternative for custom dependency resolution logic.