Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

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 (wink).

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

compile goal

test goal

run goal

assembly

scope compile

This dependency is needed for compilation of the main source, for compiling and running tests, and for running the main artifact.

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 test

This dependency is needed for compiling and running tests. It is not needed for compiling the main source or running the final artifact.

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 runtime

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 provided

?

?

?

?

scope optional

?

?

?

?

<optional></optional>

  • No labels