Maven is a build automation tool.
What does build automation mean? - It means compiling and packaging your JAVA code in such a way that is consistent across machines. Maven also makes the build process really easy.
Consider this: with no build system, you have to take care of several particulars like:
There are several more advantages like:
The biggest advantage of using Maven is dependency management. Prior to Maven, there was Ant. However, Ant didn't have in built dependency management and used Ivy for it. Maven improves on that by having in-built dependency management features.
There are two kinds of dependencies: direct and transitive. As the names suggest direct dependencies are ones that the project depends on directly. Transitive dependencies are ones that direct dependencies and transitive dependencies depend on. The tricky part is, as you might have guessed, transitive dependencies. Why? Transitive dependencies of your project can depend on other projects that may depend on others and so on. As your project becomes heavy on dependencies, so does your dependency graph of transitive dependencies. The second issue is a dependency cycle. If say, module A -> module B -> module C -> module B (-> represents depends on), we have a dependency cycle. This is a problem because the build would go into an infinite loop with module B trying to get module C and module C trying to get module B.
Maven solves these problems using concepts like dependency mediation, management, scope, etc. The Maven site has a good tutorial on it.
Scopes define at what point of the build cycle is a dependency available. The important types are:
A Project Object Model (POM) provides all the configuration for a single project. It usually consists of these major declarations:
Maven is very modular in the sense every bit of configuration can be handled with plugins. Maven plugins can be configured to run specific goals/phases with certain configuration parameters. Let's take the example of the maven-surefire-plugin.
Take for instance, the phase
integration-test. The goal for it is
test which tells Maven to run it as a
test phases aka it tells Maven, run them as tests. It also says Maven should include all files that matches the regex
This will let you run phases like
mvn surefire:integration-test. As the configuration suggests, it will pull all files that matches the regex, and run them as tests. A few important phases are: