How to add project dependencies in Maven?

In Maven, project dependencies can be managed by adding dependencies to the project’s pom.xml file.

To add project dependencies, you need to add a subtag within the tag in the pom.xml file, and specify the coordinates of the dependency in that subtag as shown below:

<dependencies>
    <dependency>
        <groupId>groupID</groupId>
        <artifactId>artifactID</artifactId>
        <version>version</version>
    </dependency>
</dependencies>

groupId represents the unique identifier of the organization or company being depended on, artifactId represents the project name being depended on, and version represents the version number being depended on.

For example, to add Apache Commons Lang dependency, you can add the following code to the pom.xml file.

<dependencies>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.12.0</version>
    </dependency>
</dependencies>

After adding the dependencies, simply save the pom.xml file and Maven will automatically download and manage the project dependencies.

bannerAds