When trying to get my hands on the development stuff that is in fashion, there is simply no way around Maven.
Although I got a high-level understanding of what Maven is, I’d like to use the possibility of writing a blog article for getting the stuff together…
First of all, maven is a tool that supports the build process. In my blog post about DevOps, I showed this picture and I still think it’s best for understanding a lot of important things, in this case how the build process takes place in the CD/CI Pipeline:
The build process as such describes the compilation of the source code to executable code, for example a JAR or WAR-file. This can sometimes be done with the developer’s IDE, but as every developer could use his own favourite IDE, a repeatable process could not be assured.
That’s a pretty obvious reason why a tool like Maven is necessary, but besides providing a uniform build system there are other aspects where Maven aims at improving developer’s life (source: maven.apache.org):
- Making the build process easy
- Providing quality project information
- Providing guidelines for best practices development
- Allowing transparent migration to new features
How does Maven work?
Maven provides a default-lifecycle which gives the guideline for the individual implementation. maven.apache.org says:
There are three built-in build lifecycles: default, clean and site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project’s site documentation.
That’s somehow the basics about the phases. Maven can be pretty powerful and complex if you configure the phases accordingly. But to get started, this should be enough for this article.
What is also important to mention, especially if you want to use maven in a corporate environment, is the settings.xml. On a Mac, you find a new folder .m2 in your user directory after you installed maven. There inside, you can add a settings.xml if you need special settings, for example proxy settings or destinations for special repositories that are only available within your company’s network and not in the public maven repository. ApacheDoc
Maven uses an XML to manage the configurations. This XML is named pom.xml whereas POM stands for “Project Object Model”. Apache has a quite detailed documentation for pom’s role and functionalities: click.
The POM contains every information about the Maven project like dependencies, versioning, some general information like used java version or package type as target of the build process.
When working with Spring Boot, for example, the needed POM is shipped with the application, so the build process will work on every system, taking all the needed dependencies with them.
The “Maven in 5 Minutes“-tutorial describes how you can use Maven to create a project repository on your computer including a pom.xml.
How to use Maven?
Well, first of all, classic Maven has no specific UI, you control it via Command Line. For easy projects, an easy set of commands should be enough:
- mvn clean package – it runs a build process taking all your settings and results in a distributable / executable format
- mvn clean install – after building your project, it will also be installed in your local maven repository so that you can use it as dependency in other projects
- mvn spring-boot:run – if you use spring-boot, you can also run your application directly out of your console with maven: use (doc)
When having issues, please make sure that you are in the correct folder within your terminal 🙂
some of the sources I used to wire the dots:
- (book, german:) “Continuous Delivery” by Eberhard Wolff, amazon