What is Maven used for in a Java project?
Options
- Only to run the program once it has been built
- Building the project and managing its dependencies (Correct option)
- Writing the documentation for the whole project
- Editing the source code files of the project
Answer
Building the project (compile, test, package) and managing dependencies, driven by a pom.xml file
Why
Maven is a build tool. You describe the project in one file, pom.xml (Project Object Model): its name and version, the libraries it needs (dependencies) and the plugins to use.
With one command (mvn package) Maven downloads the libraries, compiles the code, runs the tests and creates the JAR or WAR.
It follows "convention over configuration": source in src/main/java, tests in src/test/java, output in target/. Gradle is a popular alternative.
Remember
Maven = pom.xml describes the project; commands build it.