What Is New in Gradle 3
Gradle 3.0 introduces significant performance enhancements, new dependency management features, and foundational support for upcoming Java versions. This release focuses on faster builds and more efficient dependency resolution.
| Category | Key Changes |
|---|---|
| Performance | Compile avoidance for Java projects, improved incremental compilation. |
| Dependency Management | Introduction of the java-library plugin, compile classpath separation. |
| Java Support | Early support for Java 9 module path and improved tooling API. |
| Deprecations | Legacy dependency configurations like compile are softened to warnings. |
| Plugins | Gradle Portal replaces Bintray JCenter for plugin publishing and resolution. |
How does Gradle 3 make my Java builds faster?
The core speed boost comes from compile avoidance. If a dependent library changes only its internal API (private methods), Gradle can skip recompiling modules that use it. This is a game-changer for large multi-project builds.
Incremental compilation for Java is also more robust. It now handles annotation processing better and tracks changes at the individual class level, leading to fewer unnecessary recompilations. You get these benefits automatically with the Java plugin.
What's the big deal with the new java-library plugin?
It finally provides a clear, formal way to declare API versus implementation dependencies. Before this, the compile configuration was used for everything, which bloated the runtime classpath and hid dependency leaks.
Key configurations:
api: Dependencies you expose in your public classpath.implementation: Dependencies used only internally.
This separation reduces unnecessary recompilation downstream and results in smaller, correct runtime classpaths. It's a must-adopt for any library project.
Is Gradle 3 ready for Java 9 modules?
It offers preliminary, experimental support. You can use the new --module-path option for compiling and running tests, which is a step towards full Java Platform Module System (JPMS) integration.
The tooling API has been updated to better handle Java 9, making IDEs like IntelliJ IDEA more stable when dealing with new module descriptors. This is foundational work; full support would come in later releases as the Java 9 spec solidified.
Why did the plugin portal change, and how does it affect me?
Gradle moved from Bintray's JCenter to its own Gradle Plugin Portal for hosting and resolving plugins. This gives the Gradle team more control over availability, security, and performance.
For most users, the build script plugin block automatically uses the new portal. If you have custom repository setups for plugins, you might need to add maven { url "https://plugins.gradle.org/m2/" }. The old JCenter URL eventually became unreliable.
FAQ
I see warnings about 'compile' configuration. Is my build broken?
No, your build still works. The compile, runtime, testCompile, and testRuntime configurations have been deprecated in favor of api and implementation. Gradle 3 issues warnings to encourage migration. You should update your build scripts for long-term compatibility and better performance.
Does compile avoidance work with annotation processors?
Yes, but with caveats. Gradle's incremental compilation now has better awareness of annotation processors. However, if an annotation processor generates API code, compile avoidance might be disabled for that specific task to ensure correctness. It's smarter than before but remains conservative.
Can I use the java-library plugin for Android projects?
Not directly. The java-library plugin is for standard Java projects. Android uses its own plugin (com.android.application or com.android.library), which has its own dependency configurations (like implementation). The concepts are similar, but the plugins are different.
What happens if I don't migrate from the deprecated configurations?
In Gradle 3, they are still functional but produce warnings. In practice, you can delay the migration, but you miss out on the compile avoidance benefits for API dependencies. Future major versions of Gradle were planned to remove them entirely, so migration is strongly advised.
How do I try the Java 9 module path support?
You can use the --module-path option passed to the compileJava and test tasks. This was an early adopter feature and required careful setup of your module descriptors (module-info.java). The support was experimental and primarily for testing the ecosystem.