Sobes.tech
Junior — Middle

What levels of dependency scope are supported in Maven?

sobes.tech AI

Answer from AI

Maven supports the following main scope levels for dependencies:

  • compile (default): the dependency is available in all build phases and at runtime.
  • provided: the dependency is needed for compilation but is not included in the final artifact, as it is expected to be provided by the runtime environment (e.g., servlet API).
  • runtime: the dependency is not needed for compilation but is required during execution.
  • test: the dependency is used only for testing and is not included in the final artifact.
  • system: similar to provided, but requires specifying a path to a local file; usage is not recommended.

Example:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>

This allows flexible management of when and where dependencies are available.