Apache Maven: Convention Over Configuration for Builds
Maven standardizes your build process using a 'convention over configuration' model, defining project structure and dependencies declaratively. It's the backbone of many Java projects, ensuring consistent builds. The footgun is fighting its conventions.
WHY IT EXISTS: Before Maven, Java projects were often built using tools like Apache Ant. Ant scripts were imperative, telling the build system how to do every step. This meant every project's build was a unique, handcrafted script, making it difficult for new developers to get started and hard to maintain consistency across an organization.
THE MENTAL MODEL: Think of Maven as a universal instruction manual for a software project. Instead of writing a custom script, you provide a declarative manifest, the pom.xml (Project Object Model). This file describes what your project is, what it depends on, and what artifacts it produces. Maven then uses its built-in conventions to figure out how to build it.
HOW IT WORKS: The core of Maven is the pom.xml file. This XML file defines the project's coordinates (groupId, artifactId, version), its dependencies, and any plugins. When you run a Maven command, it executes phases of a standard build lifecycle. Common phases include compile (compiles source code), test (runs unit tests), and package (bundles the code into a distributable format like a JAR). Maven automatically downloads declared dependencies from a remote repository like Maven Central.
WHEN TO USE IT: Maven is the standard for many Java applications, especially in enterprise environments where consistency and dependency management are critical. It excels in multi-module projects, where it can manage dependencies and build order across many related sub-projects. Its common interface is ideal for CI/CD pipelines.
WHEN NOT TO USE IT: For very simple projects, Maven can feel like overkill. Its XML-based configuration can be verbose compared to modern alternatives like Gradle, which uses a Groovy or Kotlin DSL for more flexible build scripts. For this reason, Gradle is the default build tool for Android development and is often preferred for projects requiring complex, non-standard build logic.
ONE CANONICAL EXAMPLE: A basic Java project would have a pom.xml file with a <dependencies> block listing a <dependency> on JUnit. When a developer runs mvn package, Maven reads the POM, downloads JUnit if needed, compiles the main code, compiles and runs the tests, and finally creates a JAR file in the target/ directory.
Read the original → en.wikipedia.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.