• TestingDocs
TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Apache Maven

Maven Dependencies, Plugins and Repositories

Maven

Overview

In this post, we will discuss Maven dependencies , plugins and repositories. Maven project might be dependent on other artifacts. These can be other libraries or even other projects. Maven will automatically discover all the dependencies either direct or transient. This is the most useful feature of Maven.

Dependencies

Dependencies are specified with <dependencies> tag in the pom.xml file. It has three main commonly used tag nodes as shown
groupId : group of related artifacts
artifactId: specific artifact id
version: version of the artifact

Other nodes:
type: Corresponds to POM packaging ( jar, war etc )
scope: scope of the artifact

Transitive Dependencies

Each dependency can have dependencies,when you specify one dependency, it can bring its own dependencies in, which are transitive. Conflicts between versions can be resolved by using <excludes> tag in <dependency>
You can run goal “dependency:tree” to see all dependencies brought in by pom. Alternatively, use dependency hierarchy in Eclipse to resolve conflicts in the  POM file.

Sample dependency in a POM file shown below:

<dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8.8</version>
</dependency>
<dependency>
         <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
</dependency>

 

Plugins

Plugins are defined in the <plugins> section, under <build> section.They have groupId, artifactId, version, and other optional <configuration> and <execution> sections. Default groupId for plugins is org.apache.maven.plugins

Sample plugin

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.4</version>
</plugin>

 

Maven Repositories

Maven Repository is an HTTP server containing hierarchy of directories. Artifacts are stored under groupId / artifactId / version. Repositories are configured in <repositories> and <pluginRepositories> sections.
Default repository is Maven Central (http://repo.maven. apache.org/maven2/). We can also setup our own repositories as well and serve from a web server.

 

Maven_Local_Repository

Local Repository

The local repository is a local folder that is used to store all your project’s dependencies.
When you build Maven project, all dependency files will be stored in your local repository.

By default, local repository is default to .m2 folder
Local repository Setting   -> {M2_HOME}\conf\setting.xml

<localRepository>home/maven_repo</localRepository>

  • Local cache of plugins and dependencies, located in ${HOME}/.m2/repository (by default  : this is configurable)
    ● Maven checks here first for plugins and dependencies, then goes to configured repositories
    ● When you execute “mvn install”, the products of your build get installed in the local repository, so they are available for other builds

Central and Remote Repository

Maven will check your pom.xml file, to identify which dependency to download. First, it will get the dependency from your local repository , if not found, then it gets from the default central repository.

 

Maven Tutorials on this website can be found at:
https://www.testingdocs.com/apache-maven-tutorial/

For more details on the Apache Maven, visit the official website at:
https://maven.apache.org/

Related Posts

Maven Download Verification Win11

Apache Maven /

Download Maven on Windows 11

Invalid Target Java Error

Apache Maven /

Fix Fatal Error compiling: Invalid target release in Maven Project

Maven Project from archetype

Apache Maven /

Create Maven Project from Archetype in NetBeans

Create New Project

Apache Maven /

Create a Maven Project skip archetype

Maven Download Button

Apache Maven /

Install Maven on Ubuntu Linux

‹ Understanding Maven Repositories› Maven dependency management in Eclipse

Recent Posts

  • How to secure your SQL Database: Tips and Tricks
  • Shaping the Future of Development: Exploring Key Trends in Software Engineering
  • Improving Java Performance with Multithreading
  • Difference between PHP and JavaScript?
  • Bing Conversation Styles
  • ChatGPT Introduction
  • Open Source AI Frameworks
  • Artificial Intelligence Tools
  • Top AI Music Applications
  • Top AI Website Design Tools

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com