On this page
Apache Maven
Prev: Jackson | Up: third_party/java | Next: Gradle
Rel: OpenJDK Distributions & Toolchain, Gradle, JUnit 5
Ref: Apache Maven Official Documentation | Maven Central
Tags: #public #prog #java #third-party #build-tool #tier/core
Overview
Apache Maven is a declarative, convention-over-configuration build and dependency management tool driven by a single XML Project Object Model (pom.xml). Every artifact in the Java ecosystem is identified by GAV coordinates: groupId:artifactId:version.
Standard Directory Layout
my-app/
├── pom.xml
├── mvnw / mvnw.cmd # Maven Wrapper (pins exact Maven version in git)
└── src/
├── main/
│ ├── java/ # Production source code
│ └── resources/ # Config files, templates (copied to classpath)
└── test/
├── java/ # Unit & integration tests
└── resources/ # Test fixtures
Minimal pom.xml (Java 21 + JUnit 5)
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo-app</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<maven.compiler.release>21</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<!-- BOM (Bill of Materials) aligns transitive versions cleanly -->
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Default Build Lifecycle Phases
Running a phase executes all earlier phases in order:
validate → compile → test → package → verify → install → deploy
| Command | Action |
|---|---|
./mvnw test |
Compiles main & test sources and runs unit tests (Surefire) |
./mvnw verify |
Runs unit tests, packages JAR, and runs integration tests (Failsafe) |
./mvnw clean package |
Deletes target/ and builds a fresh .jar |
./mvnw dependency:tree |
Inspects transitive dependencies and version conflicts |
Dependency Scopes
compile(default): Available at compile, test, and runtime; propagated transitively.test: Available only during test compilation and execution (e.g., JUnit).runtime: Needed at runtime, not compile time (e.g., JDBC drivers, SLF4J backends).provided: Supplied by the runtime container or JDK at runtime (e.g., Servlet API, annotation processors).
Linked from
Related notes
- tuts/third_party/java/gradle Linked here; links to this page; shared tags: #java, #prog, #tier
- tuts/third_party/java/jackson Linked here; links to this page; shared tags: #java, #prog, #tier
- tuts/third_party/java/junit Linked here; links to this page; shared tags: #java, #prog, #tier
- tuts/third_party/java Linked here; links to this page; shared tags: #java, #prog
- tuts/third_party/java/spring_boot links to this page; shared tags: #java, #prog, #tier
- tuts/third_party/java/spring_framework links to this page; shared tags: #java, #prog, #tier
- tuts/java links to this page; shared tags: #java, #prog
- tuts/java/jvm_and_openjdk/openjdk_distributions_and_toolchain Linked here; shared tags: #java, #tier
- tuts/interop/java_and_c_ffm_and_jni shared tags: #java, #prog, #tier
- tuts/java/builtins/AutoCloseable shared tags: #java, #prog, #tier