Hero Background

Next-Gen App & Browser Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

What is the difference between plugins and dependencies?

In Maven, a dependency is an external library your code needs to compile, test, or run, while a plugin is a tool that executes tasks during the build. Dependencies are declared in the <dependencies> element and added to your classpath by scope; plugins are declared in <build><plugins> and run goals that are bound to build lifecycle phases. Put simply, dependencies are what your project uses, and plugins are how your project is built.

What Is a Maven Dependency?

A dependency is a versioned artifact, almost always a JAR library, that your source code references. When you declare a dependency, Maven resolves it from your local .m2 cache or a remote repository such as Maven Central, Nexus, or Artifactory, then places it on the classpath so your code can compile and run against it. A dependency is passive: it supplies code, but it does not perform any action by itself.

Dependencies are declared inside the top-level <dependencies> element, each identified by a groupId, artifactId, and version. An optional scope controls which classpath the dependency appears on and whether it is passed on transitively:

  • compile: The default scope. The library is available on the compile, test, and runtime classpaths and is inherited transitively by projects that depend on yours.
  • provided: Needed to compile and test, but expected to be supplied at runtime by the JDK or a container (for example, the Servlet API). Not transitive.
  • runtime: Not required to compile, only to run, such as a JDBC driver. Present on the runtime and test classpaths.
  • test: Available only when compiling and running tests, such as JUnit, TestNG, or Mockito. It never reaches your production classpath.
  • system / import: Niche scopes for pointing at a local file path or importing a managed dependency list (a BOM) inside <dependencyManagement>.

A typical test-scoped dependency in What Is Pom in Maven? looks like this:

<dependencies>
  <dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.10.2</version>
    <scope>test</scope>
  </dependency>
</dependencies>

What Is a Maven Plugin?

A plugin is a tool that actually does the work of the build. Maven is a plugin-execution framework, so every real task, compiling code, running tests, packaging a JAR, or deploying an artifact, is performed by a plugin. A plugin bundles one or more goals, and each goal is a single executable task such as compiler:compile or surefire:test. Goals bind to phases in the build lifecycle (validatecompiletestpackageverifyinstalldeploy), so they run automatically when that phase executes.

Build plugins are declared inside <build><plugins>, while reporting plugins live in <reporting><plugins>. Importantly, a plugin runs inside Maven's own plugin classloader, not on your project's classpath, so a plugin's internal dependencies never leak into your application. The example below configures the surefire plugin to run a TestNG suite during the test phase:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>3.2.5</version>
      <configuration>
        <suiteXmlFiles>
          <suiteXmlFile>testng.xml</suiteXmlFile>
        </suiteXmlFiles>
      </configuration>
    </plugin>
  </plugins>
</build>

For a fuller catalogue of build and reporting plugins and the phases they bind to, see What Are the Different Plugins Used for Maven?.

Plugins vs Dependencies: Side-by-Side Comparison

AspectDependenciesPlugins
What it isA library or artifact your code usesA tool that runs tasks during the build
RolePassive, provides code to callActive, performs build actions
Declared in<dependencies><build><plugins> or <reporting><plugins>
When usedCompile, test, runtime (classpath)Build time (lifecycle phases)
Unit of workVersioned artifact (groupId:artifactId:version)Goal bound to a phase
Configured by<scope><configuration>, <executions>, phase / goal
ClasspathAdded to the project classpathRuns in Maven's plugin classloader
Exampleselenium-java, junit, testngmaven-compiler-plugin, maven-surefire-plugin

Key Differences Explained

  • Purpose: A dependency adds capability to your code by supplying a library; a plugin adds capability to your build by supplying a task. One is content, the other is process.
  • Where declared: Dependencies go in <dependencies>; build plugins go in <build><plugins>. Mixing them up, for example trying to add a library under <plugins>, is a common cause of "class not found" errors at runtime.
  • When used: Dependencies are consumed at compile, test, or runtime through the classpath. Plugins execute at build time, only while a lifecycle phase is running.
  • Unit of work: A dependency is a single artifact identified by coordinates and a version. A plugin's unit of work is a goal that you bind to a phase or invoke directly with mvn plugin:goal.
  • Classpath isolation: Dependencies join your project's classpath and resolve transitively. A plugin's own dependencies stay in the plugin classloader and never become your project's dependencies.
  • Versioning: Both are versioned, but a dependency version pins the library your code compiles against, whereas a plugin version pins the behaviour of a build step, which is why locking plugin versions keeps builds reproducible.

How They Work Together in a pom.xml

In a real project the two cooperate. Your What Is Maven Dependency? list might include selenium-java and testng so your test classes compile, while your <build><plugins> section configures the surefire plugin to actually run those tests. The dependencies provide the code; the plugin provides the action that exercises it. When you run mvn test, Maven walks the lifecycle to the test phase, surefire's test goal fires, and it executes the suite using the classes loaded from your test-scoped dependencies.

Because the surefire plugin simply launches your JUnit, TestNG, or Selenium tests, you do not have to touch your plugin or dependency setup to widen coverage. By pointing your WebDriver remote URL at a cloud Selenium grid, the same mvn test command can run the suite across many browser and operating-system combinations in parallel. TestMu AI provides such a grid: you keep your existing Maven dependencies and plugins and run the tests across 3000+ real browser and OS environments on the Selenium cloud, which slots neatly into a Maven-based CI pipeline.

Frequently Asked Questions

What is the difference between a plugin and a dependency in Maven?

A dependency is an external library your code needs to compile, test, or run; it is declared in <dependencies> and added to the project classpath. A plugin is a tool that executes goals during the build lifecycle, such as compiling code or running tests; it is declared in <build><plugins>. Dependencies are passive code your project uses, while plugins actively perform actions during the build.

Where are dependencies and plugins declared in pom.xml?

Dependencies are declared inside the top-level <dependencies> element, each with a groupId, artifactId, version, and optional scope. Plugins are declared inside <build><plugins> for build plugins, or inside <reporting><plugins> for reporting plugins.

Are dependency scopes the same as plugin phases?

No. A scope (compile, provided, runtime, test, system, import) controls which classpath a dependency appears on. A phase is a stage of the build lifecycle that a plugin goal binds to, such as compile, test, or package. Scopes apply to dependencies; phases and goals apply to plugins.

Can a Maven plugin have its own dependencies?

Yes. A plugin can declare its own <dependencies> block, which Maven loads into the plugin's classloader so the plugin can run. These plugin dependencies do not become part of your project's compile or runtime classpath, so they never leak into your application.

Why does Maven need both plugins and dependencies?

Maven separates what your project uses from how it is built. Dependencies supply the libraries your source code references, while plugins supply the build logic that compiles, tests, and packages that code. Maven itself does almost nothing without plugins, so both are required for a working build.

Is a dependency the same as a library?

In practice, yes. A Maven dependency is a reference to a versioned artifact, usually a JAR library, that Maven downloads from a repository and places on your classpath. The term dependency emphasizes that your code depends on that library to compile or run.

Related Questions

Test Your Website on 3000+ Browsers

Get 100 minutes of automation test minutes FREE!!

Test Now...

KaneAI - Testing Assistant

World’s first AI-Native E2E testing agent.

...

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests