This project has been migrated from Apache Maven to Gradle, utilizing the current stable release of Gradle (9.3.0). The migration maintains all functionality while adding enhanced capabilities for standalone application packaging.
- Gradle Version: 9.3.0 (current stable release as of January 2026)
- Java Version: 21 (using Java Toolchain)
- Build Tool: Gradle with Wrapper (platform-independent)
- build.gradle - Main build configuration file (replaces pom.xml)
- settings.gradle - Project settings and name configuration
- gradlew / gradlew.bat - Gradle wrapper scripts for Unix/Windows
- gradle/wrapper/ - Gradle wrapper JAR and properties
All Maven dependencies have been successfully migrated to Gradle format:
| Dependency | Version | Scope | Notes |
|---|---|---|---|
| junit-jupiter-api | 5.11.4 | test | JUnit 5 API for writing tests |
| junit-jupiter-engine | 5.11.4 | testRuntime | JUnit 5 test execution engine |
| junit-platform-launcher | 1.11.4 | testRuntime | Required for Gradle 9.x JUnit integration |
- java - Core Java compilation and build support
- application - Provides
runtask and application packaging - jacoco - Code coverage reporting (version 0.8.12)
- shadow - Creates standalone executable fat JARs (version 9.0.0-beta4)
The project uses Gradle's Java Toolchain feature to ensure Java 21 is used consistently:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}Main class is configured for execution:
application {
mainClass = 'hw.Main'
}Code coverage is configured to:
- Run automatically after tests
- Exclude
Main.javafrom coverage metrics (pedagogical reasons) - Generate both XML and HTML reports
The project now uses the Shadow plugin (formerly known as shadow-jar) to create standalone executable JARs. This plugin:
- Bundles all dependencies into a single JAR file
- Configures the manifest with the correct main class
- Creates a "fat JAR" that can run anywhere with Java installed
Running ./gradlew shadowJar produces:
build/libs/hello-java-1.0-SNAPSHOT-all.jar
This JAR can be executed standalone:
java -jar build/libs/hello-java-1.0-SNAPSHOT-all.jar [args...]Example:
$ java -jar build/libs/hello-java-1.0-SNAPSHOT-all.jar test arg1 arg2
args = [test, arg1, arg2]
hello world
2024
bye for now| Maven Command | Gradle Equivalent | Description |
|---|---|---|
mvn clean |
./gradlew clean |
Clean build artifacts |
mvn compile |
./gradlew compileJava |
Compile source code |
mvn test |
./gradlew test |
Run tests |
mvn package |
./gradlew build or ./gradlew package |
Build project |
mvn verify |
./gradlew check |
Run verification tasks |
mvn exec:java |
./gradlew run or ./gradlew exec |
Execute main class |
| N/A | ./gradlew shadowJar |
Create standalone fat JAR |
# Clean and build the project
./gradlew clean build
# Build without tests
./gradlew build -x test
# Create standalone JAR
./gradlew shadowJar
# Alias for shadowJar (Maven-style)
./gradlew package# Run the application
./gradlew run
# Run with arguments
./gradlew run --args="arg1 arg2 arg3"
# Alias for run (Maven-style)
./gradlew exec# Run all tests
./gradlew test
# Run tests with coverage report
./gradlew test jacocoTestReport
# Run specific test class
./gradlew test --tests TestHelloWorld
# Run tests continuously (on file changes)
./gradlew test --continuous# View dependency tree
./gradlew dependencies
# View test dependencies only
./gradlew dependencies --configuration testRuntimeClasspath
# Check for dependency updates
./gradlew dependencyUpdates# List all tasks
./gradlew tasks
# List all tasks including detailed descriptions
./gradlew tasks --all
# View project properties
./gradlew propertiesThe source directory structure remains unchanged from Maven:
hello-java-maven/
├── build.gradle # Gradle build configuration
├── settings.gradle # Gradle project settings
├── gradlew # Unix Gradle wrapper script
├── gradlew.bat # Windows Gradle wrapper script
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── src/
│ ├── main/
│ │ └── java/
│ │ └── hw/
│ │ ├── HelloWorld.java
│ │ └── Main.java
│ └── test/
│ └── java/
│ └── hw/
│ └── TestHelloWorld.java
└── build/ # Gradle build output (gitignored)
├── classes/
├── libs/ # Contains generated JARs
├── reports/ # Test and coverage reports
└── test-results/
| Artifact Type | Maven Location | Gradle Location |
|---|---|---|
| Compiled classes | target/classes/ |
build/classes/java/main/ |
| Test classes | target/test-classes/ |
build/classes/java/test/ |
| JAR files | target/*.jar |
build/libs/*.jar |
| Test reports | target/surefire-reports/ |
build/reports/tests/test/ |
| Coverage reports | target/site/jacoco/ |
build/reports/jacoco/test/ |
Gradle 9.x supports configuration cache for faster builds. Enable it by adding to gradle.properties:
org.gradle.configuration-cache=trueGenerate detailed build analysis:
./gradlew build --scanEnable parallel test execution in build.gradle:
test {
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}Two alias tasks have been added for Maven users:
- package - Calls
shadowJar(Maven-style packaging) - exec - Calls
run(Maven-style execution)
- Faster Builds: Gradle's incremental compilation and build cache
- Better Dependency Management: Transitive dependency resolution
- Flexible Scripting: Groovy/Kotlin DSL for complex build logic
- Rich Plugin Ecosystem: Easy integration of new build tools
- Standalone Packaging: Built-in support for fat JAR creation
- Modern Tooling: Active development and Java 21+ support
# Stop all Gradle daemons
./gradlew --stop
# Check daemon status
./gradlew --status# Force clean build
./gradlew clean build --no-build-cache# Update to latest Gradle version
./gradlew wrapper --gradle-version=9.3.0# View dependency insight
./gradlew dependencyInsight --dependency junit-jupiter- Java 21: Required by project configuration
- Gradle 9.3.0: Uses Shadow plugin beta (9.0.0-beta4) for compatibility
- JUnit 5: Platform launcher explicitly included for Gradle 9.x
- IDE Support: Works with IntelliJ IDEA, Eclipse, VS Code with Gradle extensions