What are Scopes in pom.xml file

The Scope tag element can take 6 values.

  • compile
  • test
  • provided
  • runtime
  • system
  • import

This scope is used to limit the transitivity of a dependency, and also to affect the classpath used for various build tasks.

maven dependency will look like below

<dependency>
    <groupId>com.konghq</groupId>
    <artifactId>unirest-java</artifactId>
    <version>2.2.00</version>
    <scope>provided</scope>
 </dependency>

Compile:

This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project.

Test:

This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.

System:

This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.

Runtime:

This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.

Provided:

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. And is not transitive.

Import:

is available from Maven version 2.0.9 for pom and it should be replaced by effective dependency from this file dependencyManagement tag.