What is a Maven Dependency?

Learn more about maven dependency

In Maven, dependency is another archive—JAR, ZIP, and so on—which your current project needs in order to compile, build, test, and/or to run. The dependencies are gathered in the pom.xml file, inside of a <dependencies> tag.

Maven does the dependency management using the concept of Repositories.

Keeping your project up-to-date with the correct versions of external JAR files can be a comprehensive task. Maven has built-in dependency management. You specify in the POM file what external libraries your project depends on, and which version, and then Maven downloads them for you and puts them in your local Maven repository.

Different types of dependencies:

  • External Dependencies: An external dependency in Maven is a dependency (JAR file) which is not located in a Maven repository (neither local, central or remote repository).
  • Snapshot Dependencies: Snapshot dependencies are dependencies (JAR files) which are under development. Instead of constantly updating the version numbers to get the latest version, you can depend on a snapshot version of the project.
  • Transitive Dependencies: If your project depends on a dependency, say Dependency A, and Dependency A itself depends on another dependency, say Dependency X, then your project has a transitive dependency on Dependency X. Required transitive dependencies are automatically included in our project by Maven.
  • Exclude Dependencies: Sometimes the direct dependencies of your project may clash with the transitive dependencies of the direct dependencies. With the dependency exclusion declaration in place, whatever version of the excluded dependency that the dependency containing the exclusion is using, will be ignored during Maven’s compilation of the project.

Steps to add a dependency in Maven Project:

1) Go to https://mvnrepository.com/

2) Search for the dependency which you would like to add in your project. For example: selenium-java

3) Click on the first link from the search results. Ex – Selenium Java

4) Click on the latest version of the dependency. Ex - 4.3.0

5) Copy the dependency details and paste it in your project pom.xml.


Bijan Patel
Full Stack Test Automation Expert | Selenium Framework Developer | Certified Tosca Automation Specialist | Postman | DevOps | AWS | IC Agile Certified | Trainer | Youtuber | Blogger|

Launch your GraphyLaunch your Graphy
100K+ creators trust Graphy to teach online
𝕏
QASCRIPT 2024 Privacy policy Terms of use Contact us Refund policy