Gradle vs Maven: Installation, Wrapper, Dependency Management, Tasks, Plugins, and Why Choose Gradle
This article explains the shortcomings of Maven, shows how to install Gradle (including package‑manager and wrapper methods), demonstrates Gradle wrapper usage in IDEA, compares dependency scopes, outlines task and plugin customization, provides mirror and proxy configuration, and lists the speed, flexibility and conciseness advantages that make Gradle a superior build tool for Java projects.
1. Install Gradle
The most traditional way is to download the binary package from the Gradle website, unzip it and add it to the PATH. Because Gradle releases new versions frequently, using a package manager (e.g., scoop on Windows or the system package manager on Linux) keeps the installation up‑to‑date.
Gradle also offers a Gradle Wrapper that automatically downloads the required Gradle version when you run the wrapper script, so you can build projects without installing Gradle globally.
2. Use Gradle Wrapper
When you create a project with IntelliJ IDEA, the IDE generates the wrapper files ( gradlew , gradlew.bat , and the gradle directory). The project structure is similar to Maven’s: the .gradle files are the equivalent of pom.xml .
3. Dependency Management
Gradle’s dependency syntax is concise compared with Maven’s XML. Example:
dependencies {
testImplementation 'junit:junit:4.13'
implementation 'com.google.code.gson:gson:2.8.6'
}Gradle provides several configurations:
implementation : available at compile and runtime, but not exposed to consumers.
api : similar to implementation but exposed to consumers.
compileOnly / runtimeOnly : visible only during compilation or only at runtime.
testImplementation , testCompileOnly , testRuntimeOnly : the same scopes limited to test code.
For searching artifacts, JetBrains’ Package Search is recommended.
4. Tasks and Plugins
Gradle build files are Groovy (or Kotlin) scripts, allowing you to write custom tasks directly. For example, you can add a task that prints the size of the generated JAR with just a few lines of code, something that would require a dedicated Maven plugin otherwise.
Gradle also has a rich plugin ecosystem (e.g., gretty for running web apps on Tomcat/Jetty) that often surpasses Maven equivalents.
5. Configure Mirrors
Because Maven’s central repository can be slow in China, Gradle can use the same mirrors. Create an init.gradle script in the .gradle directory with the following content:
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" }
maven { url "https://maven.aliyun.com/repository/spring-plugin" }
maven { url "https://maven.aliyun.com/repository/gradle-plugin" }
maven { url "https://maven.aliyun.com/repository/google" }
maven { url "https://maven.aliyun.com/repository/grails-core" }
maven { url "https://maven.aliyun.com/repository/apache-snapshots" }
}
}6. Configure Proxy
If you have a corporate proxy, set it globally by creating gradle.properties in the .gradle folder:
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=all7. Why Use Gradle?
Speed: Gradle’s build cache and daemon make compilation several times faster than Maven, especially for large projects.
Flexibility: Build scripts are written in a full programming language (Groovy/Kotlin), allowing complex logic without external scripts.
Conciseness: The same functionality often requires far fewer lines than Maven’s verbose XML.
Gradle has become the default for many modern Java ecosystems (Spring, Android, etc.), so learning it is essential for Java backend developers.
— End of article.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.