Sitemap

What is MAVEN? A Dependency Manager? A Build tool? What is POM ?

6 min readAug 16, 2018

--

How would you like to understand maven ? Build tool ? Package Manager ? dependency Manager ? … Okay .. Let’s start defining every keyword I used here.

What is a Package ?

Taking Java as an example. In java , you may include all the related classes (functionality wise or any criteria) in the same package. But Why? — As Wikipedia says about the ‘Java Packages’, you want to keep things organized and you need a namespace for related classes. Furthermore, if you have used Ubuntu, you may have experienced installing packages, but not single files. In a nutshell, we can define a Package as a portion of some programs.

What is a Dependency ? and Why ?

Dependency is used to refer when something requires another thing to get executed itself. Simply, ‘A’ depends on ‘B’.

Ex: A motor car needs labourers, tools, and many types of oils to make a car. In other words, we can say these are dependencies of the car. It is not needed ‘tools’, ‘oils’ to be made in the same factory. May be car manufacturer takes them from another oil manufacturer or someone else.

The same scenario happens in the Software engineering.

In Software Engineering, programmers used to re-use different other components frequently when developing a component of a product. The main idea is to do this is to spend more energy to work on the business logic rather than developing same kind of items or components that are already available to use.

One of the practices that Maven encourages is “don’t repeat yourself”

A joke taken from https://www.monkeyuser.com/2017/npm-delivery/

Can you imagine how many dependencies you are using to build a small node or java web project s? Every component of the project is depended on some component and it is also depended on another component.. and so on. And, if you plot this dependencies into a diagram, you may get a one like this

Dependency graph from https://www.researchgate.net

Therefore, By using a dependency management tools you can solve this situation easily

What is application building ? build tool ? Why we need it ?

What is building ? — It is not only about converting a ‘.java’ file into ‘.class’ or ‘.o’ (Compiling in java)

Compiling — turning source code into a object code

Think about a situation, when you have so many parts of your project(Let’s say so many modules which contain so many files inside them) and you need to make a standalone artifact that can be run on a particular platform or directly on the computer. The process that is taken to convert these files into a executable program is called Building. This process consists set of steps such as Compiling, Linking and Packaging

Okay, then what is a build tool ?

Build tools are programs that automate the creation of executable applications from source code— techopedia.com

You may or may not be confused after hearing about this — “What the heck do I need a tool to do this? I can do this alone” . In small systems it is okay and fine (we don’t have lot to do) to follow the build process manually. But, you can’t just run commands, get all the dependencies and configure files for larger projects which have so many files with so many relationships and dependencies. Therefore, A Build tool is needed to handle this situation by following a more reliable and efficient build process. It helps you to keep track of what needs to be built, what dependencies are needed to include and in which sequence.

Tasks that a typical build tool perform — Downloading dependencies, compiling into a binary code, packaging, running tests, deployment

Example build tools : Maven, Ant, Gradle, Gulp, Webpack

What is Maven ?

Maven, a Yiddish word meaning accumulator of knowledge, was originally started as an attempt to simplify the build processes in the Jakarta Turbine project. There were several projects each with their own Ant build files that were all slightly different and JARs were checked into CVS

I hope now you have a clear idea about dependency management and build automation tools. I’ll directly come to the point by providing the list of objectives that maven attempts to achieve( these are mentioned in its official website)

  1. Make the build process easy — The programmers doesn’t need to know much about the process of how maven works or provide every configuration settings manually
  2. Provide a uniform build system — Working on a one project with maven is sufficient to work on other maven projects
  3. Provide quality project information — Maven provides user to specify the project information using the POM and make them available to use whenever needed. Some information are generated from the source of the project
  4. Provide guidelines for development best practices
  5. Allowing transparent migration to new features — Provide the ability to take advantage of updated versions of the dependencies and plugins for the same project (programmer can use updated or newly added Plugins)

What is POM ?

POM — “Project Object Model” is used to to describe about our project and many configurations that are needed by some tools or plugins that works with our project. they can be build tools or dependency managers.

If you have used “npm” before, it’s time to recall your memory about package.json.

Why POM as a .XML file ? — XML means Extensible Markup Language. Normally XMLs are used to store information. It provides user a better format of describing contents. See the example below.

<Users>
<User>
<FirstName>John</FirstName>
<LastName>Cena</LastName>
<Country>USA</Country>
</User>
<User>
<FirstName>Michael</FirstName>
<LastName>Jackson</LastName>
<Country>USA</Country>
</User>
</Users>

Therefore, having your project details in a .xml makes things easier.

POM.xml stores the informations and configurations of the project project that are used by Maven for the building process

Sample POM.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"   
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion><groupId>com.javatpoint.application1</groupId>
<artifactId>my-application1</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Maven Quick Start Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

POM.xml contains — Details of the project, Repositories, Dependencies, Plugins, Build resources, Reporting output, Profiles and few more.

When you are creating a maven project you will be given a default POM.xml. Which has default values as such as src/main/java for source directory;src\test\javafor the test directory; jar for packaging and more.

When a maven goal or a task is executed, it reads the POM and gets the configuration information, then run the goal. Example for a goal: You type mvn package in the terminal.

When you are developing a maven project, Do we need to give every information to the POM ?

No. It has a Super POM which is used as the Maven’s default POM for projects. Every Maven project inherit the super POM. Unless you have explicitly specified your configurations and dependencies you are using, it will set to its default values.

But, every maven projects is needed to have at least these POM details (It’s called minimal POM)

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>

Maven support both inheritance and aggregation for POMs when you have same dependencies and configurations for the modules of the projects. You just need to add few details to the POM.xml

Ex: <Parent> and <Modules>

For more details :

https://maven.apache.org/guides/introduction/introduction-to-the-pom.html

I hope you have got a better idea about Dependency management, what is Maven and the work that POM does.

Please feel free to comment and give your suggestions✋ 😄

References

  1. https://www.nexb.com/blog/introduction_to_software_dependencies.html
  2. https://maven.apache.org
  3. https://www.techopedia.com/definition/16359/build-tool

--

--

Dulaj Dilshan
Dulaj Dilshan

Written by Dulaj Dilshan

Developer @ Ballerina | Software Engineer @ WSO2 | Studied Engineering @ University of Moratuwa

Responses (1)