Katie
Katie

Reputation: 1031

Maven is successfully built with the current version of a dependency, but still references to an older version

I have the current version of the dependency successfully installed in the local mvn .m2 registry with mvn clean install (confirmed by cd into .m2 repository).

I then modified the pom.xml of the project to include the new version number:

        <dependency>
            <groupId>com.xyz.lib</groupId>
            <artifactId>xyz-lib-abc-model</artifactId>
            <version>1.4.0-SNAPSHOT</version>
        </dependency>

Maven was able to build successfully with 1.4.0-SNAPSHOT, but when I accessed the project in IntelliJ, it linked to an old version (0.1.1-SNAPSHOT) instead of the current version.

When I checked the dependency tree using `mvn dependency:tree, I have:

[INFO] +- com.xyz.lib:xyz-lib-abc-model:jar:1.4.0-SNAPSHOT:compile

Which looks correct to me.

I have tried using <dependencyManagement> but then it makes the project failed to build, and failed to detect the model.

Anyone knows what's going on and how to get maven to pull the correct version?

Thank you in advance!

Upvotes: 0

Views: 2109

Answers (4)

lombocska
lombocska

Reputation: 222

my first guess goes to the used maven type in your IDEA is not the one that you use in the terminal. :)

IDEA preferences You can set up the installed maven instead of the bundled one.


Or another solution is that you proceed a “refresh/reimport” in pom.xml. It will investigate the classpath based on your pom.xml and refresh the ones that needed.

You should see the "Reimport button here Reimport

If you don't see Maven at all, that means. you haven't added your project to IDEA as a Maven project.

Please then do the following 1. Right Click on pom.xml 2. 2. Add as a maven project add as a maven project

Upvotes: 0

Mark Bramnik
Mark Bramnik

Reputation: 42541

Try the following approach:

  1. Close the project in IntelliJ
  2. File --> Open ...
  3. Find pom.xml of your project, not the idea project files
  4. Open this pom.xml. It will re-build all the dependency model in accordance with the information found in this new pom.xml (that I assume doesn't have an old dependency anymore).

DependencyManagement section is irrelevant in this case - mention it because you've said in the question that you've tried this - so don't bother, it will save you some time :)

Upvotes: 0

Ananthapadmanabhan
Ananthapadmanabhan

Reputation: 6226

Try re-importing the dependencies from local m2 in IntelliJ like :

  • Open the project view in IntelliJ
  • Right click the pom.xml file and
  • select Maven - Reimport If this works for you IntelliJ will add the
    dependencies to the project
  • Check the if the dependencies you need are added in File - Project Structure - Project Settings - Libraries and File - Project Structure - Modules - Dependencies

Upvotes: 2

Tanimak
Tanimak

Reputation: 194

I have seen this issue with IntelliJ. If you don't need the old version anymore, you can cd to .m2 directory and delete the older version manually. But you need to keep the both versions, you can open the project as a fresh project using the pom.xml. This will solve the issue.

Upvotes: 0

Related Questions