IntelliJ uses wrong version of Maven-managed dependency

I have two versions of a jar in my .m2 directory (poi-3.1-FINAL and poi-3.2-FINAL), and even though the POM file specifies the more recent one, IntelliJ IDEA 8.0.1 insists on using the older one, even after a re-sync ("Re-import Maven projects").

What's going on, and how can I get IntelliJ to use the right version?  Conceivably both versions might need to be in my Maven repository to satisfy different projects' needs.

My .m2:

$ find .m2/repository/org/apache/poi/
.m2/repository/org/apache/poi/
.m2/repository/org/apache/poi//poi
.m2/repository/org/apache/poi//poi/3.1-FINAL
.m2/repository/org/apache/poi//poi/3.1-FINAL/poi-3.1-FINAL.jar
.m2/repository/org/apache/poi//poi/3.1-FINAL/poi-3.1-FINAL.jar.sha1
.m2/repository/org/apache/poi//poi/3.1-FINAL/poi-3.1-FINAL.pom
.m2/repository/org/apache/poi//poi/3.1-FINAL/poi-3.1-FINAL.pom.sha1
.m2/repository/org/apache/poi//poi/3.2-FINAL
.m2/repository/org/apache/poi//poi/3.2-FINAL/poi-3.2-FINAL.jar
.m2/repository/org/apache/poi//poi/3.2-FINAL/poi-3.2-FINAL.jar.sha1
.m2/repository/org/apache/poi//poi/3.2-FINAL/poi-3.2-FINAL.pom
.m2/repository/org/apache/poi//poi/3.2-FINAL/poi-3.2-FINAL.pom.sha1

My POM.xml:

        <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
                <version>3.2-FINAL</version>
            </dependency>

I'm using Mac OS X 10.5.6, and I have Maven 2.0.9 installed locally, although I don't know if IntelliJ is using it or not.

Thanks,
Kevin

8 comments
Comment actions Permalink

I can't reproduce this problem ever since I deleted poi-3.1-FINAL from the .m2 repository and re-downloaded it.

I'll mark this question as answered even though it's not ....

*If* it is a real IntelliJ problem, it's pretty subtle (some sort of IntelliJ caching issue?  complicated by upgrade?)  However, if it's real, it could be very unpleasant if there are no API conflicts between two versions of a dependency, but IntelliJ is nevertheless using the wrong one.

No need to reply.  IntelliJ and I are friends again.

1
Comment actions Permalink

Is it possible this is an IntelliJ bug?  When I carefully renamed/tweaked the 3.1-FINAL and 3.2-FINAL version files to be 3.1 and 3.2 (I also changed the archetype .pom and .pom.sha1 file for each version), then IntelliJ did the right thing when I changed the version string in the project pom.xml.  Does IntelliJ malfunction when it sees version strings that don't look like x.y[.z] where x, y, and z are integers?

-Kevin

0
Comment actions Permalink

even though it can be an IDEA problem, or a Maven Embedder problem, you should try running

mvn dependency:resolve

to make sure the dependencies are what you expect

0
Comment actions Permalink

Sergei,

Thanks for your comment.  However, I found this article (http://docs.codehaus.org/display/MAVENUSER/Improving+Maven2+Dependency+Resolution), which states:

Maven 2.0.x Dependency Features

...

  • Version - Currently this is very overloaded. Version can represent a fixed version or a range. Version can also be represented with build numbers and by keywords like (SNAPSHOT for date) (RELEASE for latest). Finally version can also be represented as free text (e.g. 3.0-RC2). The resolution of which artifact matches a version spec is deterministic but some combinations are not possible to specify such as the 4th build of 3.0-BETA (i.e. 3.0-BETA-4).
  • Classifier - This might be new for 2.1. Currently the M2 resolver doesn't use it. The current documentation suggest its use for additional matching (perhaps for vendor, JDK version, etc.)
0
Comment actions Permalink

If I'm not mistaken IDEA does not use the straight "maven" but rather maven embedder which is based on maven 2.1 codebase

0
Comment actions Permalink

Another data point: after deleting the poi-3.1-FINAL subtree from the .m2 directory tree, I then indirectly re-added it by specifying 3.1-FINAL in my pom and clicking the re-import button.  As expected, poi-3.1-FINAL was succesfully downloaded alongside the existing poi-3.2-FINAL.  What is really interesting is that from this point on, IntelliJ would correctly follow the version that I specified in the pom file. Switch to 3.2-FINAL and re-import: works.  Switch to 3.1-FINAL an re-import: works.  Now I'm really confused.

0
Comment actions Permalink

Hi Thibaud,

Thanks for your replies.  Given my recent discovery (see above in the thread), this may very well not be a 2.1-versus-2.0 issue, but ...

Assuming 2.1 features would seem to be a bit hazardous given that most POM files are written to 2.0 specs, I would imagine.  Also, it's hard to believe that the specification for <version> would not be backwards-compatible in Maven 2.1.  Finally, I just looked at the .xsd file referenced by the POM file, and it seems to indicate that unless the POM file specifies a different version of Maven, then 2.0 should be assumed.

All my remarks are conditioned by the fact that I really don't know much about Maven or even XML ;-)

Thanks,
Kevin

0
Comment actions Permalink

This is not necessarily the IDEA's fault. I think, according to maven's naming convention, FINAL is considered to be a classifier.
Try changing your dependency to:

<dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
                <version>3.2</version>
                <classifier>FINAL</classifier>
</dependency>

-1

Please sign in to leave a comment.