Search code examples
mavendependenciesversion

maven provided scope and version


<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?)


Solution

  • It depends.

    Generally speaking, if you are expecting an exact version (even if provided) then that is what you should provide.

    However, there are instances when you may need to finesse the versions a little. That being said - I would contend 2 points:

    1) It is probably ok to have your project expect a lower version and be provided with a higher version; so long as the higher version is not a major one. I would suggest taking a look at a good open source versioning model, such as an Apache project.

    2) It is probably NOT ok to have your project expect a higher version and get a lower one. The main reason being that you can't expect things that may not be there.

    I hope this helps.