Repaso
Español
Maven, Git & SDLCIntermediateVCS-05

What do the Maven dependency scopes compile, provided, runtime and test mean?

Options

  1. They are the names of branches used in a Git repository
  2. Build and run, build only, run only, and tests only (Correct option)
  3. They define the author and license of each library
  4. They are the version numbers of a Maven release

Answer

compile: needed to build and run; provided: needed to build but supplied by the runtime; runtime: not needed to compile but needed to run; test: only for tests

Why

The scope controls when a dependency is on the classpath:

  • compile (default): always, and it is packaged.
  • provided: available at compile time but not packaged, because the server provides it (e.g. the Servlet API in an external Tomcat).
  • runtime: not needed to compile, needed at execution (e.g. a JDBC driver).
  • test: only when compiling and running tests (JUnit, Mockito).
<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter</artifactId>
  <version>5.10.2</version>
  <scope>test</scope>
</dependency>

Remember

test = tests only; provided = server gives it; runtime = needed only to run.

Key terms

Practice this question in Repaso