Insights hero banner (short)

Insights

Bringing our best ideas and thinking to you.

  • Blog Post
  • Application Development

Blog Post

November 11, 2016

Share this page:

Maven is a tool every Java Developer should embrace

By Chris Harris

My journey with Maven started in 2006, while working for a Big Ten University in the USA. Since then, I have gained 11 years of experience working with it, transforming my journey from hate to disciple. Maven is an open source build tool that manages dependencies and is extremely useful for Java-based projects. At the time, Maven had been out for almost 3 years and was a buzz word in technology circles. At first, like any new piece of software, there is a learning curve. Especially with open source, the documentation is at times sporadic, and Maven definitely fell into this mold.

So, my personal journey with Maven started with hate. What made it challenging was that Maven had a certain way of execution - not exactly the way I would have done it myself in those days. Back when I first started there was little information on build lifecycle - after I figured out when and how to use build phases in the lifecycle I was hooked!

From that point on, my journey went towards disciple. I moved back to Canada and worked for a company that was also into open source software and they wanted to use Maven. Here, we were pushing Maven to its limits by creating multiple build scenarios using assembly plugins to removing conflicting classes in dependency jars.

Why use Maven? The benefit is that users can specify which files and formats to include into an output artifact. This is instrumental for reconstructing dependency jars to remove and add certificates to work in a Java Network Launch Protocol (JNLP). Another incredible Maven plugin is the replacer -- it can modify the parameters needed to build certain components, which can be changed at key phases in the build process.

Based on my experience with Maven, here is the best advice I can give to someone starting out:

  1. Read articles on phases and lifecycles - this will definitely help you take full advantage of what you can do with Maven. Here are a couple of links to articles that helped me:
  2. The parent project object model (POM) should be directly above the child POM. Although it can function if placed elsewhere, you will make the life of the people who touch your code much easier!
  3. Group common dependencies together and use properties to specify the version. This will be beneficial for the first time you have to upgrade.
  4. Don't be afraid to use comments or descriptions in your POM. Remember that sooner or later, someone else will need to support it.
  5. Take advantage of the reporting in Maven. Not only can you create Javadocs, but also issues tracking, Jar licenses, and dependency reports, to name a few.
  6. If creating a project from scratch, try and use the archetype. This will create the base structure that Maven and your application will require.
  7. If you are using custom repositories, place them within your master POM rather than in your settings file. You may only need to use this custom repository with this project and its unnecessary to add extra repositories that you may not need after the project is complete.

Overall, there are tons of tips to make your life easier using Maven. If you download a Java source from git, or are hooking an application up to a continuous integration (CI) tool, the de facto method of use is Maven.

Learn it and live it - it will make your life with Java much easier.