Stage 1 - Maven: The Foundation of Java Project Builds

A Java project stops being simple as soon as it has several packages, resources, tests, external libraries, and a final file that must run on another machine. At that moment javac Main.java is no longer a realistic build process.

A build tool is a program that turns source code into a predictable artifact. It compiles code, copies resources, runs tests, downloads dependencies, creates a JAR or WAR, and can publish the result.

Stage 1 - Maven: The Foundation of Java Project Builds

Why this topic exists

Maven appeared to solve the chaos of custom Ant scripts and different project layouts. Its main idea is Convention over Configuration: if a project follows standard conventions, Maven already knows where production code, resources, tests, and output should live.

The standard layout is part of the contract. src/main/java contains application Java code. src/main/resources contains files that must be available on the runtime classpath. src/test/java contains test code. target is generated output and should not be committed.

pom.xml means Project Object Model. It describes project coordinates, Java version, dependencies, plugins, packaging type, and sometimes parent or module relationships. A minimal POM is enough for Maven to understand how to compile and package a project.

The lifecycle is a chain of phases. validate checks basic project correctness. compile compiles main code. test runs tests. package creates the artifact. verify runs extra checks. install puts the artifact into the local repository. deploy uploads it to a remote repository.

A goal is a concrete plugin action, such as compiler:compile or dependency:tree. A phase is a lifecycle checkpoint. When you run mvn package, Maven executes all previous phases and invokes the plugin goals bound to them.

Build flow

  1. source code.
  2. pom.xml.
  3. lifecycle phase.
  4. plugin goals.
  5. artifact.

This sequence is the mental model to keep while reading build files. The names are different in Maven and Gradle, but the practical question is the same: what input is used, what task runs, what output is produced, and where that output is stored.

Concrete example

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.academy</groupId>
  <artifactId>orders</artifactId>
  <version>1.0.0</version>
  <properties>
    <maven.compiler.release>17</maven.compiler.release>
  </properties>
</project>

Useful reference

Concept Meaning
mvn clean Deletes target so the next build starts from a clean output directory.
mvn compile Compiles production source code.
mvn package Runs previous phases and creates the JAR or WAR.
mvn install Stores the artifact in ~/.m2 for local reuse.
mvn dependency:tree Shows the full dependency graph.
mvn dependency:analyze Finds declared-but-unused and used-but-undeclared dependencies.

How this is used in real projects

Use Maven when you want a stable, widely understood Java build with strong conventions and predictable dependency management. Its XML can feel verbose, but the tradeoff is that most Java developers can open a Maven project and immediately understand the build.

In a team setting, build knowledge is not optional theory. It affects local development, CI time, dependency upgrades, release stability, and debugging. When a Spring service fails to start after a dependency change, when CI downloads a different library version, or when an artifact cannot be deployed, the answer is usually in the build configuration, dependency graph, packaging step, or repository setup.

Common mistakes

  • Copying configuration without understanding which layer of the build it affects.
  • Treating a local successful build as proof that CI and production delivery will work.
  • Ignoring dependency trees, generated output, and repository rules until a release fails.
  • Mixing application runtime configuration with build-time configuration.
Glossary
build tool
A program that automates compiling, testing, packaging, dependency resolution, and other project build steps.
build
The process that turns source code, resources, tests, and configuration into a usable artifact.
Maven
A Java build tool based on conventions, lifecycles, plugins, and the `pom.xml` project model.
Gradle
A flexible build tool that uses tasks, plugins, build scripts, and incremental execution.
pom.xml
The Maven project file that describes coordinates, dependencies, plugins, properties, and build settings.
build.gradle
The Gradle build script that declares plugins, repositories, dependencies, tasks, and build configuration.
dependency
An external library or module that a project needs to compile, test, or run.
dependency coordinates
The group, artifact, and version values used to identify a dependency exactly.
scope
A Maven setting that defines where a dependency is available, such as compile, runtime, or test.
configuration
A Gradle dependency bucket, such as implementation or testImplementation.
transitive dependency
A dependency that is brought in indirectly because another dependency needs it.
dependency tree
A view that shows direct and transitive dependencies and helps diagnose version conflicts.
multi-module project
A project split into several modules that can share configuration and depend on each other.
parent project
A Maven project that centralizes shared configuration for child modules.
aggregator
A Maven project that lists modules and lets Maven build them together.
plugin
An extension that adds behavior to a build tool, such as compiling, testing, packaging, or publishing.
profile
A named build configuration variant used for different environments or build needs.
BOM
Bill of Materials, a dependency version catalog that keeps related libraries on compatible versions.
packaging
The build step and project setting that defines the output artifact type, such as JAR or WAR.
artifact
A built output such as a JAR, WAR, or published library version.
repository
A storage location where build tools download dependencies from or publish artifacts to.
Maven Central
The main public repository for Java and JVM libraries.
snapshot
A changing development artifact version that is not treated as a stable release.