Junior — Middle
Can you list the types of scope in Maven and their features?
sobes.tech AI
Answer from AI
In Maven, the scope of a dependency determines in which build and runtime phases it is available. Main types of scope:
- compile (default): the dependency is available in all phases — compilation, testing, and runtime.
- provided: the dependency is needed for compilation and testing but is not included in the final artifact, as it is expected to be provided by the runtime environment (e.g., servlet API in a container).
- runtime: the dependency is not needed for compilation but is required during runtime and testing.
- test: the dependency is used only for testing, not included in the final artifact, and not available during runtime.
- system: similar to provided, but requires an explicit path to the jar file on the local machine; usage is not recommended.
Example of using scope in pom.xml:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>