01 - Introduction to Maven

1. Introduction

            1.1 Description         

            1.2 Maven vs Ant

            1.3 Maven 3 vs Maven 2.x

 

1.1 Description

For programmers build tools are not the most attractive subjects. The best build tool is a piece invisible and stable that helps the programmers to save useful time and let them concentrate on the implementation of the code.            

Build tools are used basically for compiling in order to create an image for all the code of the project. By the time the build tools added beside compiling other useful features like:

     - management of the project dependencies

     - handling management tasks

     - adapting to the changing of the product requirements

     - automatization .

 

In this tutorial we can learn about Maven which is the most popular build tool on the market with the greatest number of users and the most preferred build tool by the Java developers.

With Maven, programmers do not have to create a build process themselves, they only have to declare life-cycle goals and dependencies for the project.

Maven helps the companies to standardize:

      - the programming rules

      - locations for source files

      - documentation

      - dependencies

      - output .

Maven is not only a build tool but is also a project management tool. With Maven can be used to generate reports, web sites and improve team collaboration.

1.2 Maven vs Ant

Ant and Maven are provided both by Apache and are the most common build tools used by the Java developers.

Maven and Ant are different. Maven does not replace Ant and cannot be considered the next Ant generation. But all is done in Ant it can be done also in Maven.

 Choosing Ant or Maven for a project build depends on the specific needs. For example we can choose Ant for projects which don't have explicit requirements for modularization or when is no need for a strong dependency management ( the newest libraries are used for external dependencies or definite set of dependencies ).

Ant is widely configurable and Maven uses convention rather than configuration. The goals in Maven are defined meanwhile in Ant are specific by project.

Ant build scripts are sometimes too complex when many dependent targets are used. In case of Maven complexity increases too when the project is type of multi-module. The predefined order of the life-cycles makes Maven less flexible.

Maven does not require development of the build scripts as Ant. Maven build scripts are easier than Ant build scripts because they are identical .

If a project depends on Ant build scripts or Make files these can be maintained with the aid of a Maven plugin. Plugins and repositories for Maven are reusable. The Ant scripts are not reusable.

In conclusion the most important features that could drive developers to use Maven instead of Ant are

         - standardization

         - easily integration with other technologies ( IDEs, App Servers and Continuous  

           Integration Servers )

         - strong performance

of the build system which increase productivity overall and make Maven the most eligible to be used in big organizations with global enterprise demands .

1.3 Maven 3 vs Maven 2.x          

Maven 3 came with a large liberty for project dependencies that can be retrieved from any declared repository meanwhile at Maven 2.x this could be retrieved only from Maven repositories. It is possible also to create now extensions for the declared repositories than the default Maven repositories.

Logging now is more accurate and in case of fail the error is indicated with a link to a wiki page.

Every execution of a plugin has an isolated classpath and does not depends on the first execution as in Maven 2.x which led to more issues .           

The POM is better validated when exist duplicated dependencies in the same POM  or the version of the plugin used is not specified.           

Parallel builds are supported in the Maven 3 version. In order to get such a build the plugin used have to be declared thread safe  - one new major goal from the third version of Maven. Parallel builds are not working with some integration tests.           

The existence of dependencies between the modules of the project is an important factor in deciding if the build must be serialized or executed in parallel. 

Maven 3 is backward compatible. This is new if we consider Maven 2.x vs  Maven 1.x

In Maven 3 the parent elements should not be versioned in sub modules.

Builds are faster than at Maven 2 and this is helps to improve performance and save time.                    

POM file can be written in non-XML format. Supported formats are: Groovy, Ruby, Scala, Clojure, YAML, etc and this feature can be used by downloading separately a translator tool that converts XML POM into other format. This feature is offered by Polyglot Maven tool.           

POM mixins is another feature that uses parameterized POM fragments injected in POM with simple references instead of using inheritance.           

M2Eclipse tool used for working with Maven inside Eclipse was rewritten with Maven 3 and  has improved totally its performance.           

If developers interact with Maven most of time from command line Maven Shell was created in for this purpose as a command-line interface (CLI). With this tool any Maven plugin is loaded into a single JVM instance and used after for builds.           

Finally Maven 2.x is no longer supported by Apache Maven Project Team and this is a good reason to move our projects build to Maven 3 or to choose it for the future build.

Like us on Facebook