Maven and Gradle are the two dominant build tools in the Java ecosystem, and knowing how to use both gives you flexibility across different project types and team conventions. Maven provides a well-defined project structure and a massive central repository of dependencies, while Gradle offers a Groovy or Kotlin DSL with faster incremental builds and highly customizable pipelines. This tutorial walks through installing and configuring both tools on RHEL 8, creating a project with each, and understanding when to use one over the other.
Prerequisites
- RHEL 8 (or a compatible clone such as AlmaLinux 8 or Rocky Linux 8) with
sudoaccess - Java 11 or Java 17 installed and
JAVA_HOMEset — see the OpenJDK tutorial for setup instructions - Internet access for downloading the Gradle binary and resolving dependencies
- Basic familiarity with Maven or Gradle project conventions
Step 1 — Install Maven from the AppStream Repository
Apache Maven is packaged in RHEL 8’s AppStream repository, so installation is a single dnf command with no additional repository configuration required:
sudo dnf install -y maven
mvn --version
The output will show the Maven version and the Java version it detected via JAVA_HOME. If Maven reports a different Java version than expected, verify that JAVA_HOME is exported correctly in /etc/profile.d/java.sh and re-open your terminal session.
Step 2 — Create and Build a Maven Project
Generate a standard Maven project skeleton with the quickstart archetype:
mvn archetype:generate
-DgroupId=com.example
-DartifactId=my-app
-DarchetypeArtifactId=maven-archetype-quickstart
-DarchetypeVersion=1.4
-DinteractiveMode=false
cd my-app
mvn compile
mvn test
mvn package
After mvn package completes, a runnable JAR is placed in target/my-app-1.0-SNAPSHOT.jar. You can run it with java -cp target/my-app-1.0-SNAPSHOT.jar com.example.App.
Step 3 — Configure a Maven Mirror (Optional)
If your server is behind a firewall or you use an internal artifact repository such as Nexus or Artifactory, configure a global mirror in ~/.m2/settings.xml. Create the file if it does not exist:
mkdir -p ~/.m2
cat > ~/.m2/settings.xml << 'EOF'
internal-repo
central
https://repo.example.com/repository/maven-public/
EOF
Replace the URL with your actual repository address. Maven will route all requests that would normally go to Maven Central through this mirror instead.
Step 4 — Download and Install Gradle
Gradle is not in the RHEL 8 AppStream repository, so you download the official binary distribution from gradle.org and install it manually:
GRADLE_VERSION=8.7
wget -q https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip -O /tmp/gradle.zip
sudo unzip -q /tmp/gradle.zip -d /opt
sudo ln -s /opt/gradle-${GRADLE_VERSION} /opt/gradle
sudo tee /etc/profile.d/gradle.sh << 'EOF'
export GRADLE_HOME=/opt/gradle
export PATH=$PATH:$GRADLE_HOME/bin
EOF
source /etc/profile.d/gradle.sh
gradle --version
If unzip is not installed, add it first with sudo dnf install -y unzip. The symlink at /opt/gradle lets you upgrade by installing a new version and updating the symlink without changing the profile script.
Step 5 — Create and Build a Gradle Project
Initialize a new Gradle application project and build it:
mkdir -p ~/gradletest && cd ~/gradletest
gradle init
--type java-application
--dsl groovy
--test-framework junit-jupiter
--project-name gradletest
--package com.example
--no-incubating
gradle build
The build output will be in app/build/libs/. Run the generated application with gradle run. Use gradle tasks to see all available tasks in the project.
Step 6 — Add the Gradle Wrapper to a Project
The Gradle Wrapper (gradlew) allows anyone to build your project without installing Gradle globally — the correct version is downloaded automatically. Generate the wrapper inside any Gradle project:
gradle wrapper --gradle-version 8.7
./gradlew build
./gradlew --version
Commit the gradlew, gradlew.bat, and gradle/wrapper/ directory to version control. CI systems and new team members can then run ./gradlew build with no additional setup required.
Conclusion
You have installed Maven from the RHEL 8 AppStream repository, configured an optional artifact mirror, and generated and built a Maven project from an archetype. You have also manually installed Gradle from the official binary distribution, set it on your system PATH, and created a Gradle project complete with a Wrapper for reproducible builds. Both tools are now available system-wide and ready to support Java application development.
Next steps: How to Deploy a Spring Boot Application on RHEL 8, How to Install Java (OpenJDK) on RHEL 8, and How to Configure Nexus Repository Manager on RHEL 8.