Managing Maven Project Dependencies
See Also
To make libraries and projects available to your project
during compilation, testing and execution you need to declare the
projects or libraries as dependencies.
All dependencies need to be available as artifacts in your local repository
when you build the project.
You declare a dependency by modifying the POM to add the coordinates of the artifact
you want to declare as a dependency.
All Maven artifacts are defined by a unique coordinate that consists of a group identifier (groupId),
artifact identifier (artifactId) and version.
Adding a dependency to the POM is similar to adding libraries to the classpath in an Ant-based project.
You can add a dependency to a Maven project in the following ways:
- Edit the POM in the editor. Open pom.xml in the XML editor and use
code completion to help you write the dependency elements and artifact coordinates.
- Use the Add Library dialog.
Type or search for the artifact in the Add Library dialog and click OK.
When you click OK, the IDE adds the dependency elements and artifact coordinates to pom.xml.
To open the Add Library dialog, perform any of the following steps.
- Right-click the Dependencies node in the Projects window and choose Add Dependency.
- Right-click in pom.xml in the editor and choose Insert Code (Ctrl-I) and choose Dependency.
- Right-click an artifact under the Maven Repositories node in the Services window
and choose Add as Dependency and select a project in the Add Dependency dialog box.
After you add a dependency to pom.xml,
a node for the artifact (
)
appears under the project's Dependencies node.
Artifacts that are not in your local repository are marked with a badge.
You need to have a copy of the artifact in your local repository if you
want to use it in your project.
This applies to libraries and to other projects that are described as dependencies.
Notes:
-
If a required artifact is available in a remote repository,
Maven will automatically download the artifact and any transitive dependencies
from the repository when you build the project.
Maven will use the latest available version of the artifact if no version is specified.
If the required artifact is not available in a remote repository,
you can right-click the artifact node and install the artifact manually.
- It is recommended that you store Maven software library JARs and project artifacts
in a local repository and keep the source code for projects under a version control system.
- See Also
- About Working with Maven
- Configuring Maven Settings
- Working with the Maven POM
Legal Notices