Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven provided scope

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
</dependency>

I use that dependency import at my project's pom.xml. My question is I declared 2.5 as version. However does it important to write a lower version? For example I mean that if my project uses 3.0 version and I write that 2.5 will be provided? (I mean that let's accept that 2.5 is fine and my project works well, If I don't change anything else and just change 2.5 to 2.0 does it cause to an error?)

like image 596
kamaci Avatar asked Dec 27 '10 22:12

kamaci


People also ask

What is the use of provided scope in maven dependency?

Provided. We use this scope to mark dependencies that should be provided at runtime by JDK or a container. A good use case for this scope would be a web application deployed in some container, where the container already provides some libraries itself.

What is the difference between compile and provided scope in maven?

compile This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects. provided This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime.

What are different scopes in maven?

Maven defines 6 scopes: compile, runtime, provided, system, test, and import.

What does scope mean in POM XML?

This scope indicates that you have to provide the system path. 6. import. This scope is only used when dependency is of type pom. This scope indicates that the specified POM should be replaced with the dependencies in that POM's <dependencyManagement> section.


1 Answers

The right solution is to declare the exact servlet api version used in the container to the minor.

The keyword is provided: whatever version you specify is used at compile time and for testing. At runtime it is assumed to be provided by your runtime container, e.g. Jetty.

If the actual runtime library differs from the declaration in your POM, you're inviting trouble. Whether you will or won't experience issues is a question of compatibility between the versions.

The Servlet API is backwards compatible, see: Are the Java Servlet APIs backwards compatible?

like image 61
b7kich Avatar answered Oct 04 '22 16:10

b7kich