Understanding Maven
Apache Maven is a software project management tool that makes the software development process simpler and also unifies the development process.
Important Note
You can also use another project management tool called Gradle with Spring Boot, but in this book, we will focus on using Maven.
The basis of Maven is the Project Object Model (POM). The POM is a pom.xml
file that contains basic information about a project. There are also all the dependencies that Maven should download to be able to build a project.
Basic information about a particular project can be found at the beginning of the pom.xml
file, which defines—for example—the version of the application, the packaging format, and so on. The minimum version of the pom.xml
file should contain the following:
project
rootmodelVersion
groupId
—Identifier (ID) of the project groupartifactId
—ID of the project (artifact)version
—Version of the project (artifact)
Dependencies are defined in the dependencies
section, as shown in the following pom.xml
code:
<?xml version="1.0" encoding="UTF-8"?> <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent </artifactId> <version>2.5.2</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.packt</groupId> <artifactId>cardatabase</artifactId> <version>0.0.1-SNAPSHOT</version> <name>cardatabase</name> <description>Demo project for Spring Boot </description> <properties> <java.version>11</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web </artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools </artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test </artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin </artifactId> </plugin> </plugins> </build> </project>
Maven is normally used from the command line, but Eclipse contains embedded Maven, and that handles all the Maven operations we need. Therefore, we are not focusing on Maven command-line usage here. The most important thing is to understand the structure of the pom.xml
file and how to add new dependencies to it. We will learn how to add dependencies using Spring Initializr in the next section. Later in this book, we will also add new dependencies manually to the pom.xml
file.
In the next section, we will create our first Spring Boot project and see how we can run it using the Eclipse IDE.