Module 34: Java Build Tools (Maven & Gradle)Beginner20 min read
Maven vs Gradle & Standard Project Structure
Understand src/main/java and src/test/java, Maven pom.xml lifecycle phases, and Gradle build.gradle scripts.
Key Takeaways & Core Concepts
src/main/java: Application source codesrc/main/resources: Config files (application.yml, SQL migrations, templates)src/test/java: Unit and integration tests- | Declarative XML (
pom.xml) | Groovy / Kotlin DSL (build.gradle.kts) |
Standard Directory Layout
Both Maven and Gradle standardize project layout so any Java developer can open any repository and immediately navigate it:
src/main/java: Application source codesrc/main/resources: Config files (application.yml, SQL migrations, templates)src/test/java: Unit and integration tests
Maven / Gradle GAV Coordinates
1public class Main {
2 public static void main(String[] args) {
3 String groupId = "com.codezov";
4 String artifactId = "java-platform";
5 String version = "1.0.0";
6 System.out.println(groupId + ":" + artifactId + ":" + version);
7 }
8}
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
8 lines
Note: Every library on Maven Central is uniquely addressed by its `groupId:artifactId:version`.
Maven vs Gradle
| Feature | Apache Maven | Gradle |
|---|---|---|
| Config Format | Declarative XML (pom.xml) | Groovy / Kotlin DSL (build.gradle.kts) |
| Build Model | Fixed lifecycle (clean -> compile -> test -> package -> install) | Incremental Task DAG + Build Cache |
| Wrapper | ./mvnw | ./gradlew (recommended so CI uses exact tool version) |
Practice & AssessmentJava Programming Tutorial
Test Your Understanding
Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.
Your Current Score
0 / 0 correct(0 attempted)