Creating a Maven project
These blogs are sub-blogs of the main series blogs to reduce the reading time if they already know these things.
Maven is one of the most used building tools for Spring projects in real-world scenarios. Because Maven’s such a well-known tool, you may already know how to create a project and add dependencies to it using its configuration.
In this blog, we’ll discuss creating a Maven project. Maven is not a subject directly related to Spring, but it’s a tool you use to easily manage an app’s build process regardless of the framework you use.
A build tool is a software we use to build apps more easily. You configure a build tool to do the tasks that are part of building the app instead of manually doing them. Some examples of tasks that are often part of building the app are as follows:
- Downloading the dependencies needed by your app
- Compiling the app
- Running tests
- Validating that the syntax follows rules that you define
- Checking for security vulnerabilities
- Packaging the app in an executable archive
Steps to follow
pom.xml
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.book</groupId>
<artifactId>spring-book</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<!-- For the sample we added this dependency-->
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.6.RELEASE</version>
</dependency>
</dependencies>
</project>
When you add a new dependency to the pom.xml file, Maven downloads the jar files representing that dependency. You find these jar files in the External Libraries folder of the project.