user4313427
user4313427

Reputation:

IntelliJ How to force downgrade dependency version?

I have a persistent problem with maven dependencies version changes in IntelliJ. Whenever I try to use a previous version of a library and change the dependency version in my pom.xml nothing happens. Maven continues to use the newer version of the library.

For example I want to use:

<dependency>
            <groupId>org.springframework.security.oauth.boot</groupId>
            <artifactId>spring-security-oauth2-autoconfigure</artifactId>
            <version>2.0.1.RELEASE</version>
 </dependency>

But Maven repo has version 2.0.2 saved :

<dependency>
            <groupId>org.springframework.security.oauth.boot</groupId>
            <artifactId>spring-security-oauth2-autoconfigure</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>

So for my projects version 2.0.2.RELEASE is used.

I tried reimporting the project first. Then I tried "reimpor all maven projects". Then I checked Settings > Maven > Always update snapshots. I also tried opening the project settings and deleting the dependency from there, but on reimport the 2.0.2 version will be imported in the project. For now the only thing that works is deleting manually the folder from the ".m2" folder.

Shouldn't library versions be strictly followed and shouldn't version 2.0.1 v be used for my project?

Upvotes: 0

Views: 12141

Answers (3)

Alexander Bubenchikov
Alexander Bubenchikov

Reputation: 59

Not clear what is the issue.

Repo can contain everything, no matter if dependency is present locally. Also, Idea does not resolve dependency itself, we use maven api to resolve them.

By default, maven takes dependency which is nearest to root (see https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html) Specifiying explicit dependency in root pom should force using this version.

Could you please provide mvn dependency:tree output and corresponding IDEA maven dependency diagram (if you have IU)?

If Idea resolve another dependency version than maven, please fill an issue at https://youtrack.jetbrains.com/issues

Upvotes: 0

Ed B
Ed B

Reputation: 23

If you want to enforce the use of a particular dependency version you can use:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.security.oauth.boot</groupId>
            <artifactId>spring-security-oauth2-autoconfigure</artifactId>
            <version>2.0.1.RELEASE</version>
        </dependency>
    </dependencies>
</dependencyManagement>

What this will do is exclude the dependency unless it actually gets used, and then if it does gets used it only uses the version you have specified.

Upvotes: 0

Sambit
Sambit

Reputation: 8011

The moment you change the version of the artifacts, maven will use the same version. It will never use neither new version nor the older version. Since you are using intellij, you can check which are the jar files along with their version used. See below the screenshot. You can expand the External libraries as shown below and you can check the dependencies used in pom.xml.

enter image description here

Besides, you can also check in command prompt. Go to command prompt and point to the project directory and type the following command.

mvn install dependency:copy-dependencies

You can see all the required dependencies along with version information in target folder. I suggest you not to delete the .m2 directory as you may have to download all the dependencies once again.

Upvotes: 1

Related Questions