Maven and multi-module dependencies

Hi

I'm using IDEA 7.0.3 with some Maven 2 projects.

We have a number of modules, all configured with Maven 2. Until now, I'd created a project in IDEA, then imported each pom individually, then configured the dependencies between them. For example, say we have a Maven module "frontend" and a Maven module "shared". Frontend depends on shared and imports some reusable classes from it. I'd configured the project so that the IDEA module "frontend" depended on the IDEA module "shared". By default, on loading from the POM, the IDEA module "frontend" would depend on the jars for shared, but not link the modules.

Note that in the POM for frontend, it declares shared (a version of it) as a dependency. Shared is a common module declared as a dependency for many modules in our system; it's not a Maven sub-module for, say, frontend.

This is all OK, but I was dreading synchronizing the Maven projects anymore to pick up dependencies, since at least in some previous attempts this seemed to wipe out the inter-module (IDEA module) dependencies. So today I decided to try a new tack, and created a "super POM" which lists all the top-level Maven modules in our system as sub-modules. I then opened that POM in IDEA. Worked great--I have all my modules available.

But.

IDEA doesn't pick up the relationship between the modules, say between frontend and shared. The question is if there is any way to get IDEA to figure this out automatically without me having to replace the (many) dependencies declared as JARs in each module with an IDEA module dependency. That is, by default the IDEA frontend module depends on shared-0.9.jar instead of the IDEA module for shared.

Hope this makes sense :).

Thanks!
Patrick

What I then decided to

9 comments
Comment actions Permalink

Your poms might have some special things, I'm doing the same (multimodule super pom) and dependencies are correctly configured by IDEA

0
Comment actions Permalink

Could you please try last eap and check if the problem recurs?
You can download it from http://www.jetbrains.net/confluence/display/IDEADEV/Selena+EAP.

0
Comment actions Permalink

Hi Anton

I have installed the latest EAP--it was an improvement, but two (serious) problems remain in my case:
1- it appears that IDEA will only substitute a JAR dependency for an IDEA module dependency if the version number of the module matches the version number of the dependency in the POM (more below)
2- if I go ahead and correct the dependencies, substituting JAR references for modules I have in the project, these will get wiped out on the next synchronize--basically, I can't use synchronize

About version: our modules are deployed on different schedules, basically driven by features and fixes. This means that while the version number of a parent module could be updated in all child modules when the parent is changed, in practice we don't do this.

An example would be: we have a module Shared at version 1.0. Shared has a number of reusable classes that are used across other modules. Say that there's a bug in Shared that affects only one other module, Child-1. We cut a release of Shared, 1.1, and update the dependency in Child-1 so that it refers to Shared 1.1. We then deploy those. All other modules that depend on Shared 1.0 are not updated if they don't need to be; at some time in the future they will be.

What I'm seeing is that when I synchronize, Shared, Child-1 and Child-2 will all be picked up, Child-1 will get the module dependency on Shared, because Shared's POM file lists it as version 1.1. Child-2 will get a JAR dependency on Shared-1.0.jar. I understand the reasoning behind this, but it makes my project unusable--navigation and debugging won't work reliably if the reference to Shared 1.0 is picked up before the reference to Shared 1.1, even though in this case I don't care about the difference. If I change Child-2 to refer to the module Shared, that works, but that will be removed during the next synchronization.

In most cases, I let the modules depend on each other without regard to version. This is in principle incorrect, but it hasn't caused any problems, and lets me work freely with all source files and all modules open at once. As you can imagine, I have a much more complicated set of dependencies than what I described above, and spent a few hours on Sunday fixing all my .imls to import modules instead of JARs following the last synchronize disaster. It's a bunch of (annoying) work and I've run into every time I've synchronized or tried to re-create the project from scratch.

I think IDEA is acting rationally (assuming my brief analysis of the behavior is correct), but I'd suggest a featureon synchronize, give me a before/after dependency list and let me decide which dependencies to remove. Alternately, give me a way to mark a dependency as "never replace this on synchronize, and preserve its ordering in the list". It's important to preserve the order in case a JAR does get addedI need the module dependency listed before the JAR dependency.

I need to test this further to see if I'm understanding it correctly (the docs on synchronization aren't detailed enough).

I appreciate all the hard work that went into the Maven module. For this particular project, it's of limited use to me, but I'm glad I can at least manage goals and etc.


Regards
Patrick

0
Comment actions Permalink

Did you try creating a multi module pom with a dependencyManagement section overriding versions for the dependencies that you want resolved differently ?

Although I understand your problem, this seems awkward to me, you're asking IDEA to behave differently than a normal maven build would, and this seems wrong to me. I don't ever want a project successfully working in IDEA but fail using maven CLI just because IDEA chose some different versions for some dependencies

0
Comment actions Permalink

Did you try creating a multi module pom with a dependencyManagement section overriding versions for the dependencies that you want resolved differently ?


That's one approach I will try this weekend. I didn't know that I could override version number of dependent POMs in a top-level POM. That would be a nice solution.

Although I understand your problem, this seems awkward to me, you're asking IDEA to behave differently than a normal maven build would, and this seems wrong to me. I don't ever want a project successfully working in IDEA but fail using maven CLI just because IDEA chose some different versions for some dependencies


I understand, but my situation is as it is. At least till now, I've never had a case where the builds conflicted so this hasn't been a problem. OTOH, not solving the versioning problem is not an option, as I simply can't work freely with two modules that are dependent on each other if the version numbers don't match with the current version of IDEA. Again, I understand what IDEA is doing (at least I think I do), but it doesn't fit with how I need to work with our modules.


Patrick

0
Comment actions Permalink

I'm coming in late here as I have these problems also but what is it you guys are refering to when you refer to a "multimodule super pom"

0
Comment actions Permalink

that's a pom materializing your "workspace".

It has a packaging type of "pom" and declares the other modules you want to work on (eg have them appear as modules and not just jar dependencies) as modules.

see http://maven.apache.org/pom.html#Aggregation

0
Comment actions Permalink

Oh that's certainly not how my pom file is setup right now.

Mine is setup with top level


<dependencies>
    <dependency>


...

Can you tell me if the version and group id's match and you have a pom matching known to IDEA is it suppose to remove any explicit versioned maven dependency and replace that with a module dependency?  Exactly what are the rules followed for this to happen?


0
Comment actions Permalink

I am working on a multi-module project, where module 'A' have dependency on module 'B' and vice versa. Can you help me out how to give pom entry for this in my parent pom file.

0

Please sign in to leave a comment.