Backend Development 11 min read

A Comprehensive Guide to Gradle: Installation, Wrapper, Dependency Management, Tasks, Plugins, and Mirror Configuration

This article introduces Gradle as a modern Java build tool, explains how to install it via binaries or package managers, demonstrates using the Gradle wrapper, details dependency scopes, describes custom tasks and plugins, and provides step‑by‑step instructions for configuring mirrors and proxy settings to improve download speed and reliability.

Top Architect
Top Architect
Top Architect
A Comprehensive Guide to Gradle: Installation, Wrapper, Dependency Management, Tasks, Plugins, and Mirror Configuration

Gradle is presented as a modern alternative to Maven for Java projects, addressing Maven's drawbacks such as verbose XML configuration, limited flexibility, and slower support for newer Java versions.

1. Installing Gradle – The traditional method involves downloading the binary package from the official site, but using a package manager (e.g., Linux package managers or Windows Scoop) is recommended for easier updates. The Gradle Wrapper can also be used to run Gradle without a local installation.

2. Using the Gradle Wrapper – When creating a project in IntelliJ IDEA, the IDE automatically generates the wrapper files (gradlew, gradlew.bat, and the .gradle directory). The wrapper ensures a consistent Gradle version across the team and eliminates the need for a global installation.

3. Dependency Management – Gradle uses a concise DSL for declaring dependencies, for example:

dependencies {
    testImplementation 'junit:junit:4.13'
    implementation 'com.google.code.gson:gson:2.8.6'
}

Gradle offers several dependency configurations: implementation , api , compileOnly , runtimeOnly , testImplementation , testCompileOnly , and testRuntimeOnly , providing finer‑grained control than Maven's four scopes.

4. Tasks and Plugins – Build scripts are Groovy (or Kotlin) files, allowing custom tasks to be written directly. Gradle’s flexibility enables simple tasks such as printing a JAR size, while Maven would require a separate plugin. Popular plugins like gretty (for Tomcat/Jetty) are also supported.

5. Configuring Mirrors – To accelerate dependency downloads in China, an init.gradle script can be placed in the .gradle folder with multiple Alibaba Cloud Maven repository URLs:

allprojects {
    repositories {
        maven { url "https://maven.aliyun.com/repository/public" }
        maven { url "https://maven.aliyun.com/repository/jcenter" }
        maven { url "https://maven.aliyun.com/repository/spring" }
        // additional repositories omitted for brevity
    }
}

6. Proxy Settings – If a network proxy is required, a gradle.properties file can be added with settings such as:

org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=10800
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=10800
systemProp.file.encoding=UTF-8
org.gradle.warning.mode=all

7. Why Use Gradle? – Gradle outperforms Maven in build speed (thanks to caching and the daemon), offers greater flexibility through a programmable DSL, and results in shorter, more readable build scripts. It is now the default for Android development and is increasingly adopted by Spring and other Java ecosystems.

JavaProxyBuild Tooldependency managementGradleMavenwrapper
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.