Apache Maven scopes usage situations

Asked

Viewed 4,795 times

4

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

Apache Maven has the following scopes: Compile(default), import, provided, Runtime, system and test.

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

1 answer

7


Compile

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

Provided

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

Import

Only works for dependencies like POM in part <dependencyManagement> of your file pom.xml. Basically includes all dependencies contained within the POM of dependence on their POM.

Runtime

Indicates that the dependency does not need to be in the build, but needs to be in the run.

Test

Indicates dependency is only used in the test phase.

System

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

More here: http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

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

  • First of all, thank you for answering. A curiosity, well-known application servers like Wildfly, Glassfish, Weblogic, etc., present all Javaee technologies(JPA, JTA, EJB, JSF, etc.)? Or each server has only some of these Javaee technologies?

  • 1

    Each has a variety of technologies depending on the version of each server. It is worth consulting the specification pages, inclusive, to save on making your POM.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.