Maven Dependency Scopes

Simply put, there are two types of dependencies in Maven : direct and transitive.

  • Direct dependencies are the ones that are explicitly included in the project using <dependency> tags
  • Transitive dependencies are dependencies required by direct dependencies. Required transitive dependencies are automatically included in the project by Maven.

All dependencies in the project, including transitive dependencies, can be listed using mvn dependency:tree command.

Each dependency scope affects transitive dependencies in its own way. This means that different transitive dependencies may end up in the project with different scopes. However, dependencies with scopes provided and test will never be included in the main project, since they are not transitive.

Then :

  • For the compile scope: all dependencies with runtime scope will be pulled in with the runtime scope in the project and all dependencies with compile scope will be pulled in with the compile scope.
  • For the provided scope : both runtime and compile scope dependencies will be pulled in with the provided scope in the project
  • For the test scope : both runtime and compile scope transitive dependencies will be pulled in with the test scope in the project
  • For the runtime scope : both runtime and compile scope transitive dependencies will be pulled in with the runtime scope in the project

Previous Next

Leave a Reply

Your email address will not be published. Required fields are marked *