Task X: Defining Dependencies

Once you've located your dependency, it's time to configure your project to use it.

Dependency Scope

Add a Depedency to your Project

Edit your project's pom.xml and add the dependency under the <depdencies> element:

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.6.1</version>
    </dependency>
  </dependencies>
</project>

You can use the dependency:resolve goal to confirm you have the right coordinates and download the dependency.

prompt> mvn dependency:resolve

Use the dependency:tree goal to generate a tree graph of your projects dependencies and any dependencies they may have.

prompt> mvn depdenencies:tree

There are several other goals for the dependency plugin. For more details use help:describe:

prompt> mvn help:describe -Dplugin=dependency