A first approach to Apache Maven
Although Apache Maven has reached version 3.1.1, many developers have not yet come into contact with this build tool.
But let's take a step back! What is Apache Maven?
Maven is a tool for managing Java projects and compiling code, which offers additional features compared to Apache Ant.
Thanks to Maven and these features, it will be easier for us to:
- Organise projects cleanly
- Standardise the structure of a project (Project - Module)
- Download libraries and resolve dependencies (using the Maven repository or other repositories, available on the web, configured in dedicated files)
- Automate tests
- Use plugins (e.g. the Maven GWT plugin)
I want to stress right away how complex Maven looks to those approaching it for the first time. Let's say that configuring a project with plugins, repositories and the various configuration files is not exactly a bed of roses the first time around. And I say this from personal experience! I lost a bit of time configuring Maven and getting “on friendly terms” with this tool, but if I have got as far as writing an article about it, it means that in the end I benefited from it.
As for the main components of Apache Maven, there are some that certainly cannot be overlooked.
Let's look at them together:
- pom.xml file: configuration file for plugins, dependencies and repositories
- goal: these are functions that can be executed on individual projects. The simplest structure for running a goal is mvn <goal_name>, such as
mvn compile, which compiles the project - repository: Maven creates the .repository folder under the user's home directory, which will be used to manage libraries
- settings.xml: configuration file for local repositories, proxies, profiles and security. This file can be specified at two levels. If it provides the configuration for a single user it is created under ${user.home}/.m2/settings.xml, whereas if it provides the configuration for all the Maven users on a machine it is created under ${maven.home}/conf/settings.xml
With this brief introduction to the main components of Maven, I conclude the first ‘getting started’ post on Apache Maven.
By the way, do any of you use it?
