This page is started because I (the first author) don't understand the dependency scope mechanism. In the first version of this page, I am trying to make sense of different sources about the topic. This means the information here is not correct per definition! The intention of this page is to get it correct and clear, so please, if you do know something about dependency scopes, change the nonsense below
.
Dependencies are defined in the POM, and are resolved transitively. However, you don't need all dependencies in all situations. That is why dependecies can have a scope defined. Furthermore, there is a tag <optional>true</optional> you can use for a dependency.
The following scopes are supported:
- compile
- test
- runtime
- provided
- tag
<optional />
In the following table, we explain the behavior of each scope for different goals. We talk about the current project, the dependency and a user project. The current project is the project whose POM we are editing. The dependency is the project the user project directly depends on. A user project is a project for which the current project is a direct depency. Consequentially, a user project has an indirect depency on the dependency. We also presume a maven2-based mechanism (goal) to run final projects.
- |
description |
|
|
|
|
|---|---|---|---|---|---|
scope |
This dependency is needed for compilation, for testing, and at runtime |
Downloaded and use dependency in the classpath. A user project will also download and use the depency. |
Downloaded and use dependency in the classpath. A user project will also download and use the depency. |
Downloaded and use dependency in the classpath. A user project will also download and use the depency. |
? |
scope |
This dependency is needed for testing the current project. It is not needed for compiling the main source or running the final product. |
dependency is not used |
Downloaded and use dependency in the classpath. A user project will also download and use the depency. A user project will not download or use the dependency. |
dependency is not used |
dependency is not used |
scope |
This dependency is needed for running the current project. It is not needed for compiling the main source or compiling or running the tests. |
dependency is not used |
dependency is not used |
? |
|
scope |
? |
? |
? |
? |
|
scope |
? |
? |
? |
? |
<optional></optional>
