Maven passes around Artifact objects (really objects that implement
Artifact) for dependencies and this object contains a file handle to the
jar in normal cases. In multimodules, when only mvn compile is run, the
file handle actually points to the target/classes folder of the
dependency. (thus the compile of the dependant jar succeeds because the
classes are on the classpath). If you were to run mvn package, then the
file handle points to the target/xxx.jar. Finally if you run mvn
install, it points to the location of the jar in the local repository. 

This causes some odd behaviors sometimes (see MDEP-98) but in most cases
it's doing the right thing. It would be more surprising to a user to run
mvn compile or mvn package and find that somehow things are compiled
against a different version than the source available on the machine.
This does present a problem though where the exact behavior is different
depending on if you run mvn from a parent project or from the child. To
be safe, just use mvn install. (I have actually set this as the
defaultGoal in my corp pom and teach my devs to just run "mvn" )

--Brian

-----Original Message-----
From: James Depaul [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, September 25, 2007 7:16 PM
To: [email protected]
Subject: Dependency resolution for modules...



Hi all -

I'm a little confused about how maven resolves dependencies that I have
defined for my project modules.  I have the following project directory
structure:

      cods (main dir )
            CodsCommon (sub-dir)
            CodsWeb (sub-dir)

I have a pom.xml file setup in cods directory, which defines CodsCommon
and
CodsWeb as two modules (CodsCommon and CodsWeb each have individual
pom.xml
files, as well).

The CodsWeb module has a dependency on CodsCommon - and requires that
CodsCommon be built first. Exerpt from pom.xml file in CodsWeb module
looks
like this:
            ...
            <dependency>
                  <groupId>maersk</groupId>
                  <artifactId>CodsCommon</artifactId>
                  <version>1.0-SNAPSHOT</version>
            </dependency>

My question is:  when I run the 'mvn compile' command it all works
properly: the dependency to Common (shown below) gets resolved even
though
the artifact does NOT seem to get installed in my .m2 local repository?!
It seems a little strange - I kind of expected my CodsCommon artifact to
be
installed after/during command execution..   So the mystery is: the
dependent module didn't get installed in .m2, but somehow this
dependency
got resolved at run-time... hence my confusion.

A little clarification please -

Thanks,
James

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to