Currently viewing the human version
Switch to AI version

What is Apache Maven?

Maven has been the default Java build tool since 2004. It downloads dependencies for you and makes every project look the same, which is boring but useful when you're switching between codebases. Every Java shop uses the same directory structure, so you always know where to find shit.

The pom.xml File (Your New Best Friend and Worst Enemy)

Everything in Maven revolves around the pom.xml file - an XML configuration that tells Maven what your project is and how to build it. This file contains:

  • Project coordinates: GroupId, ArtifactId, and Version (the holy trinity of Maven)
  • Dependencies: All the libraries you need (and their transitive dependencies you don't want)
  • Build settings: Plugins that actually do the work
  • Random metadata: That nobody reads but Maven requires anyway

The pom.xml approach means you describe what you want instead of writing build scripts. When it works, it's fine. When it breaks, you'll be staring at XML trying to figure out what went wrong. The POM reference docs help when things break, and Sonatype's guide covers publishing requirements.

Standard Project Layout (Finally, Some Sanity)

Maven enforces a standard directory layout that every Java project follows. No more guessing where the source code lives:

Maven Directory Structure

src/main/java/          # Your actual Java code lives here
src/main/resources/     # Config files, properties, anything non-Java
src/test/java/          # Unit tests (that you definitely write, right?)
src/test/resources/     # Test config files
target/                 # Maven dumps all generated stuff here

This structure is the same across every Maven project. Walk into any Java shop and you'll immediately know where everything is. It's boring but incredibly useful when you're not the one who wrote the project.

Build Phases (The Magic Incantations)

Maven has three build lifecycles, but you'll mainly care about one:

Maven Build Lifecycle Phases

  1. Default lifecycle: Compiles, tests, and packages your code
  2. Clean lifecycle: Deletes the target directory when things get weird
  3. Site lifecycle: Generates docs that nobody reads

The default lifecycle has phases like validate, compile, test, package, verify, install, and deploy. Run mvn package and Maven automatically runs compile and test first. It's actually pretty smart about dependencies between phases, though it will happily run tests that take 20 minutes every time you want to create a JAR.

Dependency Management (When It Works)

Maven's dependency management system handles the nightmare of JAR file management. Maven automatically:

  • Resolves transitive dependencies: Downloads all required libraries, including their dependencies
  • Manages version conflicts: Uses dependency mediation to resolve version conflicts
  • Handles different scopes: Supports compile, test, runtime, and provided scopes
  • Integrates with repositories: Connects to Maven Central and other repositories with basically everything you'll ever need

This works great until you hit dependency hell - when two libraries need different versions of the same thing and Maven picks the wrong one. You'll end up running mvn dependency:tree and staring at 47 different versions of slf4j wondering why your app won't start. Maven caches everything in ~/.m2/repository which grows to several GB and occasionally corrupts, forcing you to delete it and re-download everything.

Common dependency problems that will ruin your day:

  • Jackson conflicts: Spring Boot 3.1.5 brings Jackson 2.15.2, your legacy library needs 2.12.1, runtime fails with NoSuchMethodError
  • Logging nightmares: slf4j-api 1.7.36, logback-classic 1.4.14, log4j-core 2.19.0, and commons-logging 1.2 all fighting each other until nothing logs
  • Version mismatches: Library A wants Guava 31.1-jre, library B wants Guava 28.2-android, Maven picks 30.1.1-jre and breaks both
  • Transitive bloat: Add spring-boot-starter-web, suddenly you have 47 dependencies including 3 different JSON parsers and a YAML library you never asked for

When dependencies break, use `dependency:tree` to see what's happening, `dependency:analyze` to find unused libraries, and the versions plugin to update everything. Baeldung's dependency guide explains how to exclude transitive dependencies.

Why Everyone Still Uses Maven

Maven is everywhere in enterprise Java because it's been around since 2004 and changing build tools is career suicide. I've watched three separate teams burn 6 months trying to migrate to Gradle - first team gave up when their CI randomly started failing with "Gradle daemon disappeared" errors, second couldn't get the Spring Boot plugin working with their custom deployment scripts, third one reverted after the gradle daemon started eating 4GB of RAM during builds and Jenkins started killing processes.

Your IDE already knows Maven. Your deployment scripts know Maven. That contractor who left 2 years ago wrote everything assuming Maven. The inertia is real.

Enterprises love Maven because it's boring and predictable. Your project will build exactly the same way in 5 years, assuming Oracle doesn't change their licensing again and your company doesn't decide to "go cloud native" and rewrite everything in Go.

Maven 4 (Coming Any Decade Now)

The Maven team has been working on Maven 4.0 since Java 8 was considered "modern". It's been in RC phase longer than some developers have been alive. Promises include:

  • Better performance: 20% faster builds (we'll see)
  • Improved BOM support: Because managing 200 versions manually wasn't fun enough
  • Java 17+ requirement: Finally dropping Java 8 support, only 5 years after everyone else
  • Consumer POM: Cleaner dependency declarations that will break existing tooling

Maven 4 claims backward compatibility with Maven 3, but we all know how that goes. Half your plugins will break, the other half will just stop working for mysterious reasons.

Will it ship this year? Maybe. Will your company upgrade within 3 years of release? Probably not. Enterprise Java shops are still running Maven 3.6.3 from 2019 and complaining about "stability".

Maven vs Gradle vs Ant Comparison

Feature

Apache Maven

Gradle

Apache Ant

Configuration

XML pom.xml (verbose as hell)

Groovy/Kotlin DSL (changes every release)

XML build.xml (even more verbose)

Learning Curve

2 weeks to get it, 2 years to not hate it

Steep

  • good luck with the docs

2 hours, then you realize you fucked up

Dependency Management

Central repo + transitive hell

Multiple repos + gradle.lockfile chaos

Download JARs like it's 2003

Build Performance

Slow but predictable

Fast until daemon dies

Fast because it does nothing

Convention over Configuration

✅ Standard structure (boring but works)

⚠️ Whatever you want (good luck)

❌ Figure it out yourself

IDE Integration

Native in everything

Native but gradle sync takes forever

Eclipse plugin from 2007

Enterprise Adoption

80%+ of Java shops

Growing (especially fintech)

Legacy COBOL bridge projects

Plugin Ecosystem

200+ plugins, half are broken

Everything you want exists

12 plugins, all unmaintained

Multi-module Projects

Works but version management sucks

Actually good at this

Copy-paste build.xml 47 times

Build Cache

Local ~/.m2 cache (8GB and growing)

Distributed cache (when it works)

What's a cache?

Parallel Execution

-T flag (breaks randomly)

Parallel by default

Manually fork processes

Release Management

release plugin (git nightmares)

Built-in (until it corrupts metadata)

Shell scripts and prayer

Testing Integration

Surefire (fails on Windows paths)

Native JUnit/TestNG support

Manually invoke junit.jar

Incremental Builds

Rebuilds everything anyway

Actually incremental

Rebuilds everything always

Documentation Generation

Site plugin (nobody uses it)

Dokka/Javadoc integration

Word documents

Getting Started with Maven

Installation

Installing Maven is easy on Mac and Linux. On Windows, you'll fight PATH variables for a while. Common Windows issues:

  • PATH problems: Maven in PATH but mvn command not found
  • Space-in-path issues: Installing to "Program Files" breaks scripts
  • JAVA_HOME wrong: Maven finds Java but uses wrong version
  • Permission errors: Antivirus software blocking Maven

Current Maven version is 3.9.x and needs Java 8+ to run. Install it with brew install maven or whatever package manager your OS uses.

Maven Wrapper (The Smart Choice)

The Maven Wrapper bundles Maven with your project so everyone uses the same version:

./mvnw clean compile    # Unix/macOS
mvnw.cmd clean compile  # Windows

This prevents "works on my machine" problems and means new team members don't need to install Maven. It's great until the wrapper can't download Maven due to corporate firewalls, then you'll be debugging proxy settings in ~/.m2/settings.xml.

Core Maven Commands

Maven provides a command-line interface that's predictable once you memorize the incantations:

mvn archetype:generate    # Create new project from template
mvn clean compile        # Clean and compile source code
mvn test                 # Run unit tests
mvn package             # Create JAR/WAR artifacts
mvn install             # Install to local repository
mvn deploy              # Deploy to remote repository

IDE Integration (Mostly Works)

IntelliJ IDEA

IDEA has decent Maven support when it's not having a stroke. Multi-module projects will drive you insane - you'll click "Reimport Maven projects" 47 times while IntelliJ shows that spinning wheel of death and consumes 8GB of RAM indexing the same files over and over, then crashes and corrupts its caches. Common issues that will waste your day:

  • "Cannot resolve symbol" for classes that compile perfectly with mvn compile
  • Import loops when IDEA gets confused about parent POMs and builds forever
  • Test failures that pass in IDEA but fail in mvn test because of different classpaths
  • Module dependencies disappearing after IDEA updates, because why would things just work?
  • Random freezing during Maven import on projects with 20+ modules
  • Wrong source roots after importing, so your src/main/java isn't actually recognized as source

Eclipse IDE

Eclipse's M2Eclipse plugin works fine until you try to do anything interesting. Multi-module projects require frequent workspace cleaning, Eclipse restarts, and sacrificial offerings to the plugin gods. Expect import errors that make no sense and can only be fixed by deleting .metadata and reimporting everything.

Visual Studio Code

VS Code's Java Extension Pack actually works pretty well for small projects. It's the scrappy underdog that sometimes outperforms the heavyweight IDEs. Debugging is hit-or-miss - sometimes it works perfectly, sometimes it can't find the main class that's literally right there.

Maven Central hosts 4.5 million artifacts because apparently everyone needs to publish their "hello world" library. Browse at mvnrepository.com for a less shitty interface. Contains:

  • Everything you need: Spring Boot, JUnit 5, Jackson 2.15.x, Apache Commons that hasn't been updated since 2018
  • Automatic downloads: Add to pom.xml, Maven downloads them, your security team blocks them, you spend 2 hours configuring proxy settings
  • Version hell: 47 versions of every library, Maven picks the broken one from 3 years ago
  • Global CDN: Blazing fast unless you're on conference WiFi or your ISP hates Java developers

Maven Central has every Java library except the one you actually need, which exists only in some dead company's private Nexus that went offline in 2019. Also, that critical AWS SDK version you depend on? They yanked it last week for "security reasons" and your build is now fucked.

CI/CD (Works Until It Doesn't)

Maven plays nice with GitHub Actions, Jenkins, and whatever cursed CI system your company bought from the lowest bidder in 2019. The basic setup is straightforward:

- run: mvn clean package

But prepare for these greatest hits:

  • Tests that pass locally but fail in CI because of timezone differences - usually date parsing tests that work fine in PST but explode in UTC
  • Out of memory errors during mvn package on the 1GB RAM CI runner your company cheaped out on
  • Random network timeouts downloading dependencies because the CI server is in Ohio and Maven Central is having a bad day
  • Flaky integration tests that fail 30% of the time, but management says "just retry the build" instead of fixing the actual problem
  • Build cache corruption that requires nuking the entire CI pipeline storage and starting over, losing 6 months of cached artifacts

Pro tip: Always run mvn clean package -DskipTests first to see if your code even compiles, because you'll save 15 minutes of waiting before discovering you forgot to import a class.

Multi-Module Projects (Abandon All Hope)

Large projects split into multiple modules because someone read a microservices blog post. In theory, you build just the piece you're working on. In practice, you'll spend 3 hours figuring out why user-service can't find classes from common-utils, even though IntelliJ shows everything is fine and displays a nice green checkmark.

Multi-module builds fail in ways that defy physics:

  • Circular dependencies: Module A needs B, B needs C, C needs A. Maven just throws up its hands
  • Version mismatches: Parent POM declares 1.0-SNAPSHOT, child modules use 1.1-SNAPSHOT, builds succeed locally but fail in CI
  • IDE lies: IntelliJ imports perfectly, shows no errors, but mvn clean install fails with "package does not exist"
  • Build order chaos: Maven builds modules alphabetically unless you specify <dependencies> correctly, which you won't

The Maven Release Plugin handles version bumping across 47 modules, but it's more finicky than a cat. It will fail if you have:

  • Uncommitted changes (obviously)
  • Untracked files (seriously?)
  • Wrong git branch (fuck you, develop branch)
  • Corporate firewall blocking SCM access (classic)

Expect to spend a full sprint making the release plugin work with your specific combination of Git hosting, Jenkins setup, and corporate security policies. Check Baeldung's multi-module guide for patterns that might work, but your project is special and definitely won't fit any of them.

Frequently Asked Questions about Apache Maven

Q

Should I use Maven or Gradle for my project?

A

Fuck, this question again. Look, if your team already knows Maven and you don't want to spend 3 weeks explaining why builds are suddenly failing, stick with Maven. If you actually care about build speed and can tolerate learning new syntax every time Gradle updates their DSL, go with Gradle.Real talk: Most Java companies use Maven because it's boring and no one gets fired for choosing boring. Android projects use Gradle because Google shoved it down everyone's throats.

Q

Do I need to install Maven globally or can I use it per-project?

A

Use the Maven Wrapper

  • seriously, just use it. I spent way too many hours debugging "works on my machine" issues because Bob had Maven 3.6.3 and Sarah had 3.9.4. The wrapper bundles Maven with your project so everyone uses the same version.Run ./mvnw instead of mvn and watch those version conflicts disappear. On Windows it's mvnw.cmd because of course Windows has to be different.
Q

What Java version does Maven require?

A

Maven 3.9.11 needs Java 8+ to run, but here's where it gets stupid: Maven 4.0 RC needs Java 17+. You can build Java 8 code with Maven running on Java 11 using toolchains, but good luck explaining that to your CI/CD pipeline when it starts failing.Pro tip: If you're still on Java 8 in production, Maven version compatibility is the least of your problems.

Q

Why does Maven download the wrong version of my dependencies?

A

Because Maven's "nearest wins" algorithm is dumb as rocks. It picks whichever version is closest to your project in the dependency tree, even if it's ancient. So when Spring Boot wants Jackson 2.15.2 and your legacy library wants Jackson 2.10.0, Maven picks... who the fuck knows.Fix it with <dependencyManagement> to force versions, or <exclusions> to tell transitive dependencies to piss off. Run mvn dependency:tree and prepare to stare at 200 lines of dependency hell trying to figure out why ClassNotFoundException is happening at runtime.

Q

Where are Maven dependencies downloaded and stored?

A

Everything goes to ~/.m2/repository and it grows like cancer. Mine's currently 8.2GB because apparently every Java library ever written is "essential" for microservices. This directory will randomly corrupt itself every few months, forcing you to delete it and re-download everything during a demo.You can change the location with -Dmaven.repo.local but don't, because then you'll forget and wonder why builds are taking forever on a different machine.

Q

Can Maven work with non-Java projects?

A

Technically yes

  • there are plugins for C#, Ruby, Scala, Kotlin, whatever. But it's like using a hammer to turn screws. Maven is designed for Java and the further you get from that, the more you'll hate yourself.If you need polyglot builds, just use Gradle or bite the bullet and use language-specific build tools. Your future self will thank you.
Q

How do I create a new Maven project?

A
mvn archetype:generate -DgroupId=com.example -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
```This creates a basic project structure. On corporate networks, this will fail because of proxy settings and you'll spend 20 minutes configuring `~/.m2/settings.xml` with credentials that expire next week.
Q

What is the purpose of the POM file?

A

The pom.xml is where you declare what your project is and what it needs. It's XML because someone in 2004 thought XML was the future. The POM reference explains everything, but you'll mostly copy-paste from Stack Overflow like the rest of us.

Q

How do I run tests with Maven?

A

mvn test runs unit tests, mvn verify runs everything including integration tests. Tests will randomly fail on different machines due to timing issues, file path differences, or because Mercury is in retrograde. The Surefire plugin handles this mess.

Q

Can I use Maven with Docker?

A

Yeah, but you'll end up with multi-stage builds that take forever. Use the official Maven Docker image to build your JAR, then copy it to a slim JRE image. Works great until you need to debug why the build works locally but fails in Docker because of file permissions.

Q

How do I manage different environments with Maven?

A

Maven profiles let you have different configs for dev/test/prod. They're activated by properties like -Dspring.profiles.active=prod. This works until someone forgets to activate the right profile and pushes test database configs to production. Been there, done that, got fired.

Q

What is Maven Central and how do I publish to it?

A

Maven Central has every Java library you'll ever need, plus 50,000 you don't. Publishing requires PGP signatures, proper metadata, and a blood sacrifice to the Sonatype gods. Use their OSSRH for publishing, but prepare for a bureaucratic nightmare worse than the DMV.

Q

How do I handle private dependencies or internal libraries?

A

Set up Nexus Repository or Artifactory and prepare for enterprise authentication hell. You'll configure settings.xml with credentials that work for exactly one person on your team, then spend a sprint figuring out why everyone else gets 401 errors.

Q

What plugins are essential for Java development?

A

The compiler plugin (compiles Java), surefire (runs tests), jar plugin (makes JARs). Most are included automatically, but you'll end up configuring them anyway because the defaults are always wrong for your specific use case.Don't even ask about the javadoc plugin

  • it fails if your comments have typos.
Q

How do I debug Maven build issues?

A

mvn -X gives you debug output that's 90% noise. mvn dependency:tree shows dependency hell in all its glory. mvn help:effective-pom shows the final resolved POM after Maven mangles your configuration.When all else fails, delete ~/.m2/repository, sacrifice a goat, and try again.

Essential Apache Maven Resources (Aka Your Future Bookmarks)

Related Tools & Recommendations

alternatives
Similar content

Maven is Slow, Gradle Crashes, Mill Confuses Everyone

Explore common frustrations with Maven's slowness and Gradle's instability. Learn about Mill's speed, team challenges, and crucial advice before migrating Java

Apache Maven
/alternatives/maven-gradle-modern-java-build-tools/comprehensive-alternatives
100%
tool
Similar content

Gradle Build Tool - Build Automation That Doesn't Completely Suck

The build tool you're stuck with for Android, and actually pretty good for Java when configured properly

Gradle
/tool/gradle/overview
95%
tool
Recommended

IntelliJ IDEA Ultimate - Enterprise Features That Actually Matter

Database tools, profiler, and Spring debugging for developers who are tired of switching between fifteen different applications

IntelliJ IDEA Ultimate
/tool/intellij-idea-ultimate/enterprise-features
44%
tool
Recommended

JetBrains IntelliJ IDEA - The IDE for Developers Who Actually Ship Code

The professional Java/Kotlin IDE that doesn't crash every time you breathe on it wrong, unlike Eclipse

IntelliJ IDEA
/tool/intellij-idea/overview
44%
tool
Recommended

IntelliJ IDEA 진짜 쓸만하게 만들기 - 왜 이거 제대로 안 써?

또 'Cannot resolve symbol' 에러 때문에 배포 미뤘나? 이제 좀 그만하자

IntelliJ IDEA
/ko:tool/intellij-idea/productivity-guide-korean
44%
integration
Recommended

jenkins github integration is mid but we're stuck with it

what actually works when jenkins bricks your weekend plans

Jenkins
/brainrot:integration/jenkins-github/overview
42%
tool
Recommended

Jenkins Broke Again? Here's How to Actually Fix It

integrates with Jenkins

Jenkins
/brainrot:tool/jenkins/troubleshooting-guide
42%
integration
Recommended

GitHub Actions + Jenkins Security Integration

When Security Wants Scans But Your Pipeline Lives in Jenkins Hell

GitHub Actions
/integration/github-actions-jenkins-security-scanning/devsecops-pipeline-integration
42%
tool
Recommended

Spring Boot - Finally, Java That Doesn't Suck

The framework that lets you build REST APIs without XML configuration hell

Spring Boot
/tool/spring-boot/overview
42%
news
Recommended

IBM and Google Promise Million-Qubit Quantum Computers by 2030 (Again)

Same companies that promised quantum breakthroughs in 2020, then 2025, now swear 2030 is totally different

OpenAI/ChatGPT
/news/2025-09-05/quantum-computing-breakthrough
40%
pricing
Recommended

AI Coding Assistant Pricing: Why My $10/Month Copilot Bill Hit $8,000

competes with GitHub Copilot

GitHub Copilot
/pricing/ai-coding-assistants/total-cost-ownership-analysis
40%
news
Recommended

Trump Just Killed H-1B Visas With a $100K Fee

Your Renewal Was Due Monday? Too Bad - That'll Be Like 95 Grand More Than Friday

ant
/news/2025-09-23/h1b-visa-fee-hike-tech-giants
40%
tool
Recommended

VS Code Settings Are Probably Fucked - Here's How to Fix Them

Same codebase, 12 different formatting styles. Time to unfuck it.

Visual Studio Code
/tool/visual-studio-code/settings-configuration-hell
40%
tool
Recommended

VS Code AI Integration: Agent Mode & MCP Reality Check

VS Code's Agent Mode finally connects AI to your actual tools instead of just generating code in a vacuum

Visual Studio Code
/tool/visual-studio-code/ai-integration-reality-check
40%
compare
Recommended

VS Code vs Zed vs Cursor: Which Editor Won't Waste Your Time?

VS Code is slow as hell, Zed is missing stuff you need, and Cursor costs money but actually works

Visual Studio Code
/compare/visual-studio-code/zed/cursor/ai-editor-comparison-2025
40%
tool
Popular choice

jQuery - The Library That Won't Die

Explore jQuery's enduring legacy, its impact on web development, and the key changes in jQuery 4.0. Understand its relevance for new projects in 2025.

jQuery
/tool/jquery/overview
40%
tool
Popular choice

Hoppscotch - Open Source API Development Ecosystem

Fast API testing that won't crash every 20 minutes or eat half your RAM sending a GET request.

Hoppscotch
/tool/hoppscotch/overview
38%
tool
Popular choice

Stop Jira from Sucking: Performance Troubleshooting That Works

Frustrated with slow Jira Software? Learn step-by-step performance troubleshooting techniques to identify and fix common issues, optimize your instance, and boo

Jira Software
/tool/jira-software/performance-troubleshooting
36%
tool
Recommended

Docker - 终结"我这里能跑"的噩梦

再也不用凌晨 3 点因为"开发环境正常,生产环境炸了"被叫醒

Docker
/zh:tool/docker/overview
36%
tool
Recommended

Docker Business - Enterprise Container Platform That Actually Works

For when your company needs containers but also needs compliance paperwork and someone to blame when things break

Docker Business
/tool/docker-business/overview
36%

Recommendations combine user behavior, content similarity, research intelligence, and SEO optimization