Apache Maven Scopes Usage Scenarios

4

The question is about the different values that can be assigned to the <scope> property of Apache Maven dependencies, and what criteria should I set for using each of them.

Apache Maven has the following scopes: compile , import , provided , runtime system and test .

I want to know what I should take into account when using each of these scopes.

    
asked by anonymous 29.06.2014 / 06:38

1 answer

5

Compile

The package is considered in the build. If there is packaging, dependency is included in the package.

Provided

The package is considered in the build, but is not included in the package if there is packaging.

Import

Only works for dependencies of type POM in part <dependencyManagement> of your pom.xml file. Basically includes all dependencies contained within the POM pendence of the dependency on your POM .

Runtime

Indicates that the dependency does not have to be in the build, but needs to be in the execution.

Test

Indicates that the dependency is used only in the testing phase.

System

Similar to provided , but for JARs. JARs need to be specified explicitly.

More here: link

On what to take into account for each use, this becomes clearer as you bundle your application and some errors appear. For example, the provided scope is well used when the packages belong to some standard lib of a specific application server, such as JBoss or WebLogic, where packages do not exist in a Maven repository, but they must be validated at some stage of development.

    
29.06.2014 / 07:51