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.
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 i.e. compile , provided , runtime , test , system , and import .
Dependency scopes can help to limit the transitivity of the dependencies. They also modify the classpath for different build tasks. Maven has six default dependency scopes. And it's important to understand that each scope — except for import — has an impact on transitive dependencies.
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.
runtime is useful for dependencies required for unit tests and at runtime, but not at compile time. This may typically be dynamically loaded code, such as JDBC drivers, which are not directly referenced in the program code.
Setting dependency to runtime ensure that there isn't an accidental dependency on the code, and also keeps the dependency from being transitive. So that, for example, if module A has a runtime dependency on library X, and module B depends on module A, it does not inherit the dependency on library X. Using "provided" or "compile" would cause B to depend on X.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With