Maven Dependency Scopes

Maven Dependency Scope attribute is used to specify the visibility of a dependency, relative to the different lifecycle phases (build, test, runtime etc). Maven provides six scopes : compile, provided, runtime, test, system and import.

  • compile : this is maven default scope. Dependencies with compile scope are needed to build, test and run the project. Scope compile is to be required in most of the cases to resolve the import statements into java classes source code. Those dependencies are propagated to dependent projects.
  • provided : this scope is used during build and test the project. They are also required to run, but should not be exported, because the dependency will be provided by the runtime, for instance, by the servlet container or application server. Those dependencies are not transitive.
  • runtime : this scope is used for dependencies that are not needed to build, but are part of the classpath to test and run the project.
  • test : this scope is used for dependencies that are not needed to build and run project, but are needed to compile and run the unit tests. This scope is not transitive.
  • system : this scope is similar to provided. The only difference is system dependencies are not retrieved from remote repository. They are present under project’s subdirectory and are referred from there.
  • import : this scope is only supported on a dependency of type pom in the dependencyManagement section. It indicates the dependency to be replaced with the effective list of dependencies in the specified POM’s dependencyManagement section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity  a dependency.



Leave a Reply

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