What is the difference in maven between dependency and plugin tags in pom xml?

difference between plugin and dependency in gradle
maven plugins
maven-plugin dependency
maven surefire plugin
what is dependency in maven
maven plugin tutorial
maven-compiler plugin
difference between plugin and jar

I'm new to the maven tool, I have made a project with Spring and Hibernate and they are configured in pom.xml as plugins, but JUnit is tagged under dependency. My question is what is the logic behind one as a plugin and one as dependency ?

Both plugins and dependencies are Jar files.

But the difference between them is, most of the work in maven is done using plugins; whereas dependency is just a Jar file which will be added to the classpath while executing the tasks.

For example, you use a compiler-plugin to compile the java files. You can't use compiler-plugin as a dependency since that will only add the plugin to the classpath, and will not trigger any compilation. The Jar files to be added to the classpath while compiling the file, will be specified as a dependency.

Same goes with your scenario. You have to use spring-plugin to execute some spring executables [ I'm not sure what spring-plugins are used for. I'm just taking a guess here ]. But you need dependencies to execute those executables. And Junit is tagged under dependency since it is used by surefire-plugin for executing unit-tests.

So, we can say, plugin is a Jar file which executes the task, and dependency is a Jar which provides the class files to execute the task.

Hope that answers your question!

In Maven, what is the difference between dependency and plugins , What is the difference between dependency-maven-plugin and executing a plugin from the command line, you must put the configuration tag outside Alternatively, you can specify the groupId explicitely in your pom (if you  The difference between <pluginManagement/> and <plugins/> is that a <plugin/> under: <pluginManagement/> defines the settings for plugins that will be inherited by modules in your build. This is great for cases where you have a parent pom file.

Maven itself can be described as food processor which has many different units that can be used to accomplish different tasks. Those units are called plugins. For example, to compile your project maven uses maven-compiler-plugin, to run tests - maven-surefire-plugin and so on.

Dependency in terms of maven is a packaged piece of classes that your project depends on. It can be jar, war etc. For example, if you want to be able to write JUnit test, you'll have to use JUnit annotations and classes thus you have to declare that your project depends on JUnit.

Apache Maven Dependency Plugin – Frequently Asked Questions, Using the <executions> Tag; Using the <dependencies> Tag; Using the <​inherited> Maven plugins (build and reporting) are configured by specifying a To configure the Mojo from your POM with the desired URL, timeout and options If you wish to have the object to be instantiated live in a different package or have a  But the difference between them is, most of the work in maven is done using plugins; whereas dependency is just a Jar file which will be added to the classpath while executing the tasks. For example, you use a compiler-plugin to compile the java files.

Maven – Guide to Configuring Plug-ins, It is an XML representation of a Maven project held in a file named pom.xml . Ant plugin execution, it does not stop the plugins that are executed from doing Soft requirements can be replaced by different versions of the same artifact found elsewhere in the dependency tag: Specifies the tag that this project lives under. Both plugins and dependencies are Jar files. But the difference between them is, most of the work in maven is done using plugins; whereas dependency is just a Jar file which will be added to the classpath while executing the tasks. For example, you use a compiler-plugin to compile the java files.

If you're coming from a front-end background like me, and are familiar with Grunt and npm, think of it like this:

First you would run, say, npm install grunt-contrib-copy --save-dev. This is like maven's <dependency></dependency>. It downloads the files needed to execute a build task.

Then you would configure the task in Gruntfile.js

copy: {
  main: {
    src: 'src/*',
    dest: 'dest/',

This is like maven's <plugin>/<plugin>. You are telling the build tool what to do with the code downloaded by npm/<dependency></dependency>.

Of course this is not an exact analogy, but close enough to help wrap your head around it.

Maven – POM Reference - Apache Maven, Maven also provides dependency:analyze plugin goal for analyzing the on a dependency of type pom in the <dependencyManagement> section. Each of the scopes (except for import ) affects transitive dependencies in different ways, as is the dependency management tags is available from the project descriptor​  Difference between Dependency Management and Dependencies in Maven Maven is a software management tool, use to manage information, dependencies and other things for a project. It has two mechanisms to add the dependencies of other modules/project.

Plug-ins are used for adding functionalities to Maven itself (like adding eclipse support or SpringBoot support to Maven etc.). Dependencies are needed by your source code to pass any Maven phase (compile or test for example). In case of JUnit since the test code is basically part of your code base and you call JUnit specific commands inside test suites and those commands are not provided by Java SDK therefore JUnit must be present at the time Maven is in the test phase and this is handled by mentioning JUnit as a dependency in your pom.xml file.

Maven – Introduction to the Dependency Mechanism, The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a and <​dependencyManagement/> tags in the pom.xml and determines the  This is a favorite method for companies with an intranet and need to be able to keep everyone in synch. There is a Maven goal called deploy:deploy-file which is similar to the install:install-file goal (read the plugin's goal page for more information). Set the dependency scope to system and define a systemPath.

Apache Maven Dependency Plugin – Introduction, It is an XML file. It always resides in the base directory of the project as pom.xml. project dependencies; plugins; goals; build profiles; project version; developers; mailing list. What is You can put the clean plugin inside the execution tag in pom.xml file. How to stop What is difference between Apache Ant and Maven? Maven will resolve plugin dependencies using the configured pluginRepository. Other artifact dependencies (eg. a parent pom) are resolved using repository. Note: Things available on maven central will be resolved by default so you wouldn't normally need to include repository for those.

Maven Interview Questions, S.no, Maven Plugin, Maven Dependency. 1. Preferred for most of the work, Used while task implementation by adding to the classpath. 2. differences between dependencymanagement and dependencies of maven Maven provides a way for you to consolidate dependency version numbers in the dependencyManagement element. You’ll usually see the dependencyManagement element in a top-level parent POM for an organization or project.

Explain the difference between dependency and plugin in Maven , Difference between and tag in Maven `pom.xml` . From Maven documentation:. pluginManagement: is an element that is seen along side plugins.Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one.

  • Can I someone tell me what is the different between phase and goal in execution?? As i knew the phase is talking about the life cycle of maven.. but why goal again? any hints? Sometimes i see people put life cycle keyword at goal... ??? (?.?)
  • @taymedee this SO question describes the difference: stackoverflow.com/questions/16205778/…
  • @r981 Your answer needs to be more clear. This answer is better: stackoverflow.com/questions/26292073/…
  • I think the missed point of this answer is that: the top-level dependencies are mainly used by your artifact instead of the plugins.
  • @MichaelPacheco, What I meant was, spring-plugin will perform a certain task of executing a set of code, which might be dependent on some libraries, which will be specified by the 'dependencies'. Take a different example: you need a compiler to execute a piece of code; Here, your compiler is a plugin and your code is the executable. Your compiler alone is capable of executing any code, but your code might be dependent on a library, say apache commons, which will be a dependency. Your compiler can only compile the code when the dependencies are present in the classpath. I hope it's clear now.
  • thanks for the quick reply , sorry but still i am confused as i know JUnit is also a framework and (hibernate,spring) also comes under framework only , so is that means in cases (hibernate,spring) could also be configured in dependency tags ? i hope you got my question.
  • Yes, and as far as I know there is no such thing as Spring maven plugin. Usually, Spring libs (or Hibernate, or JUnit, or TestNG etc.) are declared as dependencies for your project. If you are new to maven I'd recommend to read this very good book.
  • @AndrewLogvinov - I have a multi pom project for api automation testing. One of the maven projects has automation tests. The build section of the project pom had only 1 plugin - maven surefire plugin with reference to a suite. The entire build tag was removed. Could you please tell me what this means ? thanks.
  • great explanation!, since I am not well versed with setting up dependencies in Java, I still have a doubt, I am currently working in IntelliJ, and created a maven project, when I tried to include webdriver-ie I have two options, either include it as plugins or dependency, I included both to compare, & observed both has exactly same groupId the only difference was that the plugins didn't come with a specific version but dependency come with 0.6.685. Could you pl explain it in layman(in relation to this example) terms what's the difference, which one to use when. Any suggestion?
  • Hard to give the most exact answer without seeing your pom.xml. But a thing that should interest you is that specifying the dependency version is mandatory (in the current pom or in the parent pom if it is an inherited dependency) in any Maven version while since Maven 3 (probably a bad good idea as feature), specifying the plugin version is optional. Maven will use the last version available in the release repository where Maven finds it. (1/2)
  • Note that it is a bad way to specify a plugin. It doesn't make your build reproducible over the time (cwiki.apache.org/confluence/display/MAVEN/…) . You should see a warning in the build. So "what is the difference ?". Plugins perform tasks for a Maven build while dependency are libraries (jar or whatever) needed in the classpath during the build. If the build of your project is the same whatever the case (using library or the plugin way), it means that the plugin is helpless as not used.(2/2)