POM file also has inheritance concept means a project divided into sub-projects. So parent project has one POM file and each sub-project have own POM file with inheriting parent POM file into the parent project. So with this structure we can built a project in one step including all sub-projects or either we can build one sub-project separately.
Maven reads the pom.xml file, then executes the goal.
Whenever we are creating POM file in our project first we should decide the project group id (i.e. groupId) and its name (i.e. artifactId) and its version for versioning of project in the repository it help in identifying.
Here is a minimal POM file:
<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.dineshonjava</groupId> <artifactId>java-api-learner</artifactId> <version>1.0.0.RELEASE</version> </project>
XML elements of Maven POM file
- project-It is the root XML element of POM file.
- modelVersion-It is the sub element of project. It specifies the modelVersion. It should be set to 4.0.0.
- groupId-It is name of group or organization of project. It is the sub element of project element.
- artifactId– It is name of project (~artifact) what we are creating and it is the sub element of project element. An artifact is something that is either produced or used by a project.
- version-It specifies the version of the artifact under given group.
The above groupId, artifactId and version elements would result in a JAR file being built and put into the local Maven repository at the following path:
MAVEN_REPO/com/dineshonjava/java-api-learner/1.0.0.RELEASE/java-api-learner-1.0.0.RELEASE.jar
As above listed elements are mandatory. All POM files require at least the project element and three mandatory fields: groupId, artifactId, version.
Super POM
All Maven POM files inherit from a super POM. If no super POM is specified, the POM file inherits from the base POM just like Object class in java.
<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> <parent> <groupId>org.dineshonjava</groupId> <artifactId>parent-project</artifactId> <version>2.0</version> <relativePath>../parent-project</relativePath> </parent> <artifactId>parent-project</artifactId> ... </project>
An inheriting POM file may override settings from a super POM. Just specify new settings in the inheriting POM file
@ImageSource-tutorials.jenkov.com
An easy way to look at the default configurations of the super POM is by running the following command: mvn help:effective-pom
Spring Boot Related Topics
- Introduction to Spring Boot
- Essentials and Key Components of Spring Boot
- Spring Boot CLI Installation and Hello World Example
- Spring Boot Initializr Web Interface
- Spring Boot Initializr With IDEs
- Spring Boot Initializr With Spring Boot CLI
- Installing Spring Boot
- Developing your first Spring Boot application
- External Configurations for Spring Boot Applications
- Logging Configuration in Spring Boot
- Spring Boot and Spring MVC
- Working with SQL Databases and Spring Boot
- MySQL Configurations
- Spring Data JPA using Spring Boot Application
- Spring Boot with NoSQL technologies
- Spring Cache Tutorial
- Spring Security Tutorial with Spring Boot
- Spring Boot and MongoDB in REST Application
- Complete Guide for Spring Boot Actuator
- Microservices with Spring Boot