Home What is Maven
Post
Cancel

What is Maven

What is Maven

maven Maven defines a project structure for us

In a project, you will have dependencies, you will pick up along the course what this means. For now, it’s ok to know that this just is like that. However, if you teach yourself to work with Maven, you don’t have to worry about this, you will develop easier, less complex and faster. If you ask me to summarize Maven I will try:

1
2
3
Maven = Manage dependencies

end of my summary

Read: Maven in 5 Minutes

Read: Introduction to the Standard Directory Layout

Here is the standard Directory Layout for a quick reference. It means that when you start a Maven project, all these folders will be there, and you start your journey in src/main/java. Can you find this path on the SDL image?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
my-app
|-- pom.xml
`-- src
    |-- main
    |   `-- java
    |       `-- com
    |           `-- mycompany
    |               `-- app
    |                   `-- App.java
    `-- test
        `-- java
            `-- com
                `-- mycompany
                    `-- app
                        `-- AppTest.java

The POM

The pom.xml file is the core of a project’s configuration in Maven. It is a single configuration file that contains the majority of information required to build a project in just the way you want. The POM is huge and can be daunting in its complexity, but it is not necessary to understand all of the intricacies just yet to use it effectively.


Maven Phases

These are the most common default lifecycle phases executed.

  • validate: validate the project is correct and all necessary information is available
  • compile: compile the source code of the project
  • test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package: take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test: process and deploy the package if necessary into an environment where integration tests can be run
  • verify: run any checks to verify the package is valid and meets quality criteria
  • install: install the package into the local repository, for use as a dependency in other projects locally
  • deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects. There are two other Maven lifecycles of note beyond the default list above. They are

  • clean: cleans up artifacts created by prior builds
  • site: generates site documentation for this project Phases are actually mapped to underlying goals. The specific goals executed per phase is dependant upon the packaging type of the project. For example, package executes jar:jar if the project type is a JAR, and war:war if the project type is - you guessed it - a WAR.

Start daily exercises in the Code Gym

Start with: Start your journey to become a Java Developer

Continue with: Project Lombok

This post is licensed under CC BY 4.0 by the author.