DEV Community

Lori-Shu
Lori-Shu

Posted on

What Do I Know about Gradle?

Developers starting their careers with Java must have encountered the package manager—Maven. The software has become the standard for developing Java projects. However, have you ever heard of another build tool for Java? Gradle is capable of managing Java projects as well.

Gradle maintainers describe it as "a highly scalable build automation tool designed to handle everything from large, multi-project enterprise builds to quick development tasks across various languages." I am going to talk about how it interacts with Java.

Build Acceleration
The architecture of Gradle enables it to build with cache. If some parts of the code didn't change since the last build, Gradle will reuse the build files that correspond to the unchanged code. This significantly reduces the build time compared to building from scratch. The design is similar to another build tool "cargo" which is contained in the Rust toolchain.
Dependencies Management
Gradle supports downloading dependencies from a central repository just like Maven. Although it is convenient, it takes a lot of work for Maven to make it great. The burden of handling dependency conflicts is a nightmare for developers. Gradle tried to absorb the experience of Maven. It employs DSL (Domain-Specific Language) script to declare project metadata, dependencies etc. Originally, it corresponded to Groovy DSL (build.gradle). Iterating to modern version, it is taking a transition to Kotlin DSL (build.gradle.kts). Compared with powerful but old XML solution of Maven, Gradle achieves more clear declaration and less boilerplate code.
Remaining Limitations
Despite the fact that Gradle gained so many optimizations, there are remaining defects. First of all, the core of Gradle is written in Java so that it needs a JVM to run. Java developers all know that not only is JVM one of the most powerful features of Java but also a drawback when it comes to distribution. The user side often doesn't have a JRE or JDK installed and the JVM can make a distribution pack huge. Another problem I have encountered is the default wrapper configuration. In order to unify the Gradle version especially for Android projects, Gradle makes the wrapper configuration default but it is a pain in the cases that I just don't want to automatically download another version of Gradle.

Insight: Gradle currently supports many languages including some outside the JVM ecosystem. I recommend Java developers to try switching the long term supported projects from Maven to Gradle.

Top comments (0)