Maven
What is Maven?
Jason van Zyl wrote Maven. Apache Maven 1.0 came out in 2004. The project's list is in the pom.xml file. This name means Project Object Model. Maven Central is the shared place of libraries. mvn compile checks the code and turns it into a class file. mvn package produces the finished archive. The Java language says the rule. Maven lines up the work of using that rule. Gradle also builds Java, but it writes the list as a script. Maven keeps the list in pom.xml with a fixed shape.
What is Maven used for?
Maven is for building a Java project with the same steps and bringing a library from one list.
- Turning code into a class file
- Opening the test with mvn test
- Writing a library into pom.xml
- Producing a finished jar archive
What can you do with Maven?
With Maven you download a dependency, run the test, and build the archive. It does not write the Java program itself. When the Java version is wrong, the build stops. A library you do not know enters your project. Maven does not read a Gradle file.
Is Maven hard to learn?
One command in an empty project is easy. The difficulty is the version and the repository. Two libraries may want the same name at a different version. When pom.xml grows, it gets lost which line brings what. The local repository keeps an old file and can hide a new download. If the network is down, a package does not come from Central.
Advantages and limits
Advantage: the steps are familiar, the list is in one file, and the same build repeats on another machine. Limit: pom.xml becomes long. Maven is not Java and it is not Gradle.
Basic ideas
pom.xml is the list. A dependency is a library that is brought in. A goal is the name of one build step.
- compile translates the code
- test runs the check
- package produces the archive
- Maven Central is the shared place
A short example
This command packages the Java project in the current folder. It does not write the code itself.
mvn package
Common questions
- Are Maven and Java the same? No. Java runs the language. Maven builds the project and brings the library.
- Are Maven and Gradle the same? No. Both can build Java. Maven keeps the list in pom.xml. Gradle writes the list as a script.
- Is pom.xml the program itself? No. It is the name and the library list.