Maven support?

So, right now you can add a POM and it builds the project dependencies but I have a couple of questions.

1. how does it handle maven exclusions?

2. does it make any effort to switch "export" off?

What are the limitations and how similar can I expect it to match mvn dependency:tree in terms of the versions
it includes in the classpath?


Specifically if you are using module dependencies with pom.xml files for each can you expect IntelliJ IDEA to figure out what to not "export?" from each module's dependency list?

and when you bring in the project again from the pom.xml ie. import you lose all the export settings you had


So what it boils down to then is that if you're using maven dependencies you can forget using module dependencies since IDEA cannot correctly what the final classpath should look like and you're forced to use a separate project for each module install the artifact of the module and have the top level project refer to all dependencies as jars only. This is a hugely inconvienient way to work.


I am not sure I understand the problem you are describing. I have been using IDEA's Maven support for years now, and, while I remember some things occasionally not working properly in the past, it seems very solid now. I always have IDEA configured to use the external Maven (not bundled) to run the targets. I have never had a problem with IDEA creating a multi-module project from POMs, managing dependencies and exclusions. Could it be that the problem you are facing is within your POMs? How complex/convoluted are they?


Are you saying that in your case if you have multi module when you compile or launch you are getting the same classpath for compile that you get when you using mvn from the command line?

In my case when I launch my app in the IDEA the classpath doesn't match what I'd get at the command line thru mvn dependency:tree

I have multiple versions of jars scattered throughout and in the IDEA all versions are "exported" .... I'd expect that some of those versions should not be "exported"


Ah, I see what you are saying now... I never use the IDEA compilation when I use Maven. I always use my external Maven's compile and install, etc. - launching it via IntelliJ's Maven pane.  One of the many reasons I use Maven is that I want all my projects and builds to be IDE-agnostic. Even although I only use IDEA, I need to make sure that everything will work consistently for Eclipse users. (And I just go crazy when I see Eclipse users defining Eclipse-specific plugins in their POMs, etc., so I am obsessed about maintaining the purity of the projects.)  That also ensures that my builds are always identical to the centralized nightly/continuous builds on the server. So, I have to admit, I can't really be sure that IntelliJ is not doing something out of whack with your jars when it builds on its own. For all it's worth, in my experience, IDEA generates projects and modules quite nicely from external POMs. perhaps there's something in the POMs that "confuses" IDEA? How complex are they?


Btw whenever I add /usr/local/apache-maven-2.0.9 to my maven configuration it still complains in IntelliJ that it doesn't know the home directory for maven.


Are you sure that is the correct Maven location? Are you using a mac? On Leopard, you should have the latest Maven (v2.2 as of now) in "/usr/share/maven".


Thanks for the tip. Yeah the maven worked but only after I added M2_HOME as a global environment variable.


I want to ask about an observation I see with how IntelliJ builds the runtime classpath when launching in IntelliJ.

If I'm using maven support and I import my app's pom file so that eventually I end up with a set of module dependencies.

If I have an object graph that has different versions of artifacts within the entire graph. Why is it that a module dependency's dependencies that have lower versions of artifacts end up appearing in the classpath earlier than higher versions of those artifacts? If I assume that changes are made in a backward compatible fashion don't I always want the highest version of the artifact in my classpath?

The only way I can control this is to reorder my module dependencies in my project or turn off export for artifacts in modules that override higher versions of the same artifact.

Is this what I'm suppose to do?

Our eventual runtime classpath pretty much mirrors what you see if you mvn dependency:tree from the command line in terms of the versions of the artifacts used. What I'm looking for is for the launch classpath in IntelliJ and for a consistent approach where by the editor in IntelliJ when I'm following references to use the appropriate version of the artifact. ie. indexing has to consider which versions are appropriate for the file I'm currently viewing. Not just assume it's the first one in the classpath. Correct me if I'm wrong.


Can we ever expect to see progress in IntelliJ in this regard or am I simply using it wrong?

Is this how m2eclipse works? If I have mulitple projects open will it determine the launch classpath correctly from the maven dependency tree?

The way I'm using the tool right now doesn't result in a classpath that mirrors what the maven dependency tree actually is.

Is this all handled in the community edition the same way it is in the enterprise edition?


Any updates to this issue?

I know its been a year since the last post but I am running into similar problems.


for me it's a bad design to play with classpath entries order. if you need it, define custom classloader and make your cool stuff and choose reqiuired jar once requested. Your case is a very specific, although idea  should allow this if maven does.


resurrecting this thread
I have a big multi-module project using maven
on this project there are developpers in different part of the world (and most do not use Intellj :_|)
now I have constant problems: apparently IntelliJ re-builds its internal descriptions from the pom.xml files
each time I start IntelliJ I have new problems to face because dependencies between modules fail
so sometime I have the source code that is ok by referencing the other module code, but the binary is not the correct one (funny for debuging)
or lot of other surprises ... so I am constantly tweaking the project configuration to deal with modules dependencies
I just try to play with the GUI ("project structure") to deal with module dependencies (direct dependencies or maven ones) and by magic it may work (though I have not understood the logic)
-btw I don't understand why it is impossible to import some maven dependencies (if I have a jar version 1.1 GUI just shows version 1.0 and no way to have the one I want!)-
this said I am now stuck by a funny dependency problem: the source code says it's ok but compiling yields :
"The type XXXX  cannot be resolved. It is indirectly referenced from required .class files"
if compiled/run directly by maven everything is ok ....
I suspect this: the maven descriptions are so complex across so many modules that there may be some maven dependency anomalies
curiously maven is happy with that and runs, but IntelliJ being too clever just gets lost....


please provide detailed information on a specific problem so we could reproduce it.
The best way to get it fixed is to make and send us a simple project that we can open and see the problem.

If you have such a specific problem, please file bug request in ht ebug tracker

Anton Makeev


you are absolutely right
now how to be specific when you do not know how to reproduce the problem at a sizeable level?
there are two modules involved for sure in this specific problem but the path of maven dependencies is staggeringly big!
(and it is the whole project that suffers of endemic dependencies plagues)
so my questions were more:
     - are other people in trouble with very big maven projects?
    - what does : "The type XXXX cannot be resolved. It is indirectly referenced from required .class files" may mean ?
what I suspect is not a bug from IntelliJ but an incompatibility when maven projects have dependencies anomalies .... which I am unable fo find :_|
other IDE such as Netbeans that delegates directly to maven have no such problem (though they face other anomalies ]:))
now if you want a copy of the whole project that can be done ;) ....
thanks for replying


out of sheer despair I tried to compile the module under netbeans
it compiles !
the class files are ok
so now back to IntelliJ ... running a code in the same module: it tries to recompile those files ?:| !!
why does IntelliJ tries to recompile codes that are up to date? (and BTW that are in no way related to the code to run: they just happen to be in the same module)
as an old user of tools such as "make" I am a bit baffled by that! Is there a way to survive in a module with some unrelated codes that do not compile? (or is it a "all or nothing" strategy?)



I still cannot understand the problem you are having.
What classes are cmpiled with errors?
In which modules/dependencies are they located?
What kind of 'tweaks' of the modules configuration in IDEA do you do?

Can you point exactly what dependency causes problems?
If you can send the project - that is great.

Please create a bug report and attach the project (you can set visibility so only our teem sees it).
If you do so, please describe your problem and answer these questions there.



thanks for replying
sorry for  not being clear


I still cannot understand the problem you are having.
What classes are cmpiled with errors?
In which modules/dependencies are they located?

>>> I have two of our own classes that are ok for the IDEA sources (I mean import are not red and everything looks ok)
>>> but compiling fires the abovementionned message
>>> those classes are in let's say module A and refer to classes in module B
>>> the message is about classes in module B
>>>> so again: class Y in module A import class X in module B that looks ok when editing but compiling crashes
>>>> this is not the first time that is happening (though with a differnet flavour of crash) and I suspect that it is the maven vision that is at fault.

What kind of 'tweaks' of the modules configuration in IDEA do you do?
>>> I am trying to play with the "project structure/dependencies" default does not work, sometimes modifying this data works wonder (except in that case!)

Can you point exactly what dependency causes problems?
>>> If I knew I would be happy

If you can send the project - that is great.
>>> I can do that: how? (it will be a BIG zip!)

MODIFIED: in ftp site it is
the .idea is bound to Lsst directory
the culprit is the org-lss-ccs-shutter/trunk module
a make of this module will reproduce the error




so I wrote an "official" question about that. (I found a precise example of dysfunctionning correlation between Maven and IDEA, there are many more I coud not pinpoint and that block me)
here is the example

module A -> (depends on) moduleX
moduleB -> moduleY -> moduleX
all versions descriptions are correct in pom.xml .... except that in the pom.xml of moduleY there is an error : a <Profile> references a dependency with an erroneous version number to moduleZ
in that case: maven does compile/run but IDEA gets stuck : code in moduleA do not "see" code in moduleB
for sure this is an error from the people that wrote the poms ... my suggestion was that if IDEA detects such an inconsistency then it issues a report!


funny thing is that in my bug/feature report I thought I precised that the problem is about incorrect maven configuration.....
and the reply is "If you are sure the configuration is correct, please attach a sample project that shows the problem." :_|
apparently I was not clear enough .... ?:|
so I'll restate the problem:
----> in complex maven configurations, if there is an anomaly (for instance an inconsistency about version due to "diamond dependencies") then maven does not notice but IDEA blocks
blocking  may be a normal and coherent behaviour .... except that we are not notified of the problem  (and we spend hours thinking there is a bug in IntellIj and annoying maintainers ;))
so this is more a feature request: if the IDEA "vision" of maven dependencies has a problem it should notify the user.


the best way to show us the problem is to submit a sample projects. So far all your descriptions are too general and we cannot do much about it.


already done: see previous message
I can do another copy with a modification that starts the feature


well for those who may have maven configuration that is so FUBR that it crashes IDEA here are 2 tips:
  - delete .idea of the project , re create project , re-import all maven modules
- sometimes  IDEA does not  "see" the latest modifications on maven description when importing a maven module : on MAC reboot the machine! (it then does work!)


everytime I introduce a new module in the project I spend many hours trying to fix the fact that IDEA is lost in POMs
now again stuck by code in a module that does not want to acknowledge code in another module (though the other module is in POM dependencies and .iml dependencies!)
so now I am obliged to use Netbeans which works correctly , tells me about the POM structure graph and so on ...
well I sure prefer to use IDEA but I can't be a masochist all the time :p
So I keep IDEA for Groovy code and will be obliged to use Netbeans for the other java codes.... X-(
my suggestion: again try to trace the Maven dependencies and signal those who are faulty and may block IDEA !


Please sign in to leave a comment.