You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Mohan K R <km...@gmail.com> on 2008/11/30 00:20:23 UTC

MultiModule and DependencyManagement?

It appears that I'm missing something critical here, so please help me out.
I have a standard
multi-module project like this. (I'm using Maven 2.0.9, JDK5).

 parent (P) -
            |- module A
            |- module B
            |- module C


A,B,C all inherit from the parent P.

Now in my parent POM (P): I have a dependencyManagement section in the POM.
 <depedencyManagement>
    <dependencies>
       <dependency>
           <groupId>log4j</groupId>
           <artifactId>log4j</artifactId>
           <version>1.2.14</version>
       <dependency>
       <...  bunch of others ...>
    <dependencies>
 </dependencyManagement>

Now in module A (I have a dependency on log4j), so only thing that I provide
is (notice no version):

    <dependencies>
       <dependency>
           <groupId>log4j</groupId>
           <artifactId>log4j</artifactId>
       <dependency>
       <...  bunch of others ...>
    <dependencies>

Now in module B depends on module A so I have this in my dependency:
    <dependencies>
       <dependency>
           <groupId>${project.groupId}</groupId>
           <artifactId>module_A</artifactId> <!-- NOTICE MODULE A -->
           <version>${project.version}</version>
       <dependency>
       <...  bunch of others ...*but no log4j*>
    <dependencies>
NOTE: I do use log4j in B, but it got transitively pulled in. So far so
good.

Now Module C, depends on Module B. So what I have is:
    <dependencies>
       <dependency>
           <groupId>${project.groupId}</groupId>
           <artifactId>module_B</artifactId>           <!-- NOTICE MODULE B
-->
           <version>${project.version}</version>
       <dependency>
       <...  bunch of others ...>
    <dependencies>
Now, I do use some log4j calls (LogFactory), but for some reason log4j does
not
get pulled in transitively??? I have to explicitly give a dependency on
log4j *or*
module_A to get it to compile??

My first that was, all transitive dependencies on module_B should get pulled
in which
means module_A and in turn its transitive dependency log4j. But nothing of
this sort
is happening? Any ideas? Is it the dependecyManagement section (which has
the version)
that is messing me up, since C does inherit from P?

Thanks
Mohan K

Re: MultiModule and DependencyManagement?

Posted by Mohan K R <km...@gmail.com>.
Thanks Stevo! Forgot to metion that it does work fine in eclipse (I'm using
m2eclipse plugin
but it fails when I compile it from the CLI). I will give the above project
a shot. Thanks again
Mohan

On Sat, Nov 29, 2008 at 6:05 PM, Stevo Slavić <ss...@gmail.com> wrote:

> Hello Mohan,
>
> Attached you can find an archive with eclipse maven multi-module project
> created as one you've described, so you can see transitive dependencies are
> working as expected. Your project is obviously somewhat different than what
> you described, and it is having effect on dependencies not being passed on.
> Check dependency scope and read this<http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html>,
> maybe it will help.
>
> Regards,
> Stevo.
>
>
> On Sun, Nov 30, 2008 at 12:20 AM, Mohan K R <km...@gmail.com> wrote:
>
>> It appears that I'm missing something critical here, so please help me
>> out.
>> I have a standard
>> multi-module project like this. (I'm using Maven 2.0.9, JDK5).
>>
>>  parent (P) -
>>            |- module A
>>            |- module B
>>            |- module C
>>
>>
>> A,B,C all inherit from the parent P.
>>
>> Now in my parent POM (P): I have a dependencyManagement section in the
>> POM.
>>  <depedencyManagement>
>>    <dependencies>
>>       <dependency>
>>           <groupId>log4j</groupId>
>>           <artifactId>log4j</artifactId>
>>           <version>1.2.14</version>
>>       <dependency>
>>       <...  bunch of others ...>
>>    <dependencies>
>>  </dependencyManagement>
>>
>> Now in module A (I have a dependency on log4j), so only thing that I
>> provide
>> is (notice no version):
>>
>>    <dependencies>
>>       <dependency>
>>           <groupId>log4j</groupId>
>>           <artifactId>log4j</artifactId>
>>       <dependency>
>>       <...  bunch of others ...>
>>    <dependencies>
>>
>> Now in module B depends on module A so I have this in my dependency:
>>    <dependencies>
>>       <dependency>
>>           <groupId>${project.groupId}</groupId>
>>           <artifactId>module_A</artifactId> <!-- NOTICE MODULE A -->
>>           <version>${project.version}</version>
>>       <dependency>
>>       <...  bunch of others ...*but no log4j*>
>>    <dependencies>
>> NOTE: I do use log4j in B, but it got transitively pulled in. So far so
>> good.
>>
>> Now Module C, depends on Module B. So what I have is:
>>    <dependencies>
>>       <dependency>
>>           <groupId>${project.groupId}</groupId>
>>           <artifactId>module_B</artifactId>           <!-- NOTICE MODULE B
>> -->
>>           <version>${project.version}</version>
>>       <dependency>
>>       <...  bunch of others ...>
>>    <dependencies>
>> Now, I do use some log4j calls (LogFactory), but for some reason log4j
>> does
>> not
>> get pulled in transitively??? I have to explicitly give a dependency on
>> log4j *or*
>> module_A to get it to compile??
>>
>> My first that was, all transitive dependencies on module_B should get
>> pulled
>> in which
>> means module_A and in turn its transitive dependency log4j. But nothing of
>> this sort
>> is happening? Any ideas? Is it the dependecyManagement section (which has
>> the version)
>> that is messing me up, since C does inherit from P?
>>
>> Thanks
>> Mohan K
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>

Re: MultiModule and DependencyManagement?

Posted by Stevo Slavić <ss...@gmail.com>.
Hello Mohan,

Attached you can find an archive with eclipse maven multi-module project
created as one you've described, so you can see transitive dependencies are
working as expected. Your project is obviously somewhat different than what
you described, and it is having effect on dependencies not being passed on.
Check dependency scope and read
this<http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html>,
maybe it will help.

Regards,
Stevo.

On Sun, Nov 30, 2008 at 12:20 AM, Mohan K R <km...@gmail.com> wrote:

> It appears that I'm missing something critical here, so please help me out.
> I have a standard
> multi-module project like this. (I'm using Maven 2.0.9, JDK5).
>
>  parent (P) -
>            |- module A
>            |- module B
>            |- module C
>
>
> A,B,C all inherit from the parent P.
>
> Now in my parent POM (P): I have a dependencyManagement section in the POM.
>  <depedencyManagement>
>    <dependencies>
>       <dependency>
>           <groupId>log4j</groupId>
>           <artifactId>log4j</artifactId>
>           <version>1.2.14</version>
>       <dependency>
>       <...  bunch of others ...>
>    <dependencies>
>  </dependencyManagement>
>
> Now in module A (I have a dependency on log4j), so only thing that I
> provide
> is (notice no version):
>
>    <dependencies>
>       <dependency>
>           <groupId>log4j</groupId>
>           <artifactId>log4j</artifactId>
>       <dependency>
>       <...  bunch of others ...>
>    <dependencies>
>
> Now in module B depends on module A so I have this in my dependency:
>    <dependencies>
>       <dependency>
>           <groupId>${project.groupId}</groupId>
>           <artifactId>module_A</artifactId> <!-- NOTICE MODULE A -->
>           <version>${project.version}</version>
>       <dependency>
>       <...  bunch of others ...*but no log4j*>
>    <dependencies>
> NOTE: I do use log4j in B, but it got transitively pulled in. So far so
> good.
>
> Now Module C, depends on Module B. So what I have is:
>    <dependencies>
>       <dependency>
>           <groupId>${project.groupId}</groupId>
>           <artifactId>module_B</artifactId>           <!-- NOTICE MODULE B
> -->
>           <version>${project.version}</version>
>       <dependency>
>       <...  bunch of others ...>
>    <dependencies>
> Now, I do use some log4j calls (LogFactory), but for some reason log4j does
> not
> get pulled in transitively??? I have to explicitly give a dependency on
> log4j *or*
> module_A to get it to compile??
>
> My first that was, all transitive dependencies on module_B should get
> pulled
> in which
> means module_A and in turn its transitive dependency log4j. But nothing of
> this sort
> is happening? Any ideas? Is it the dependecyManagement section (which has
> the version)
> that is messing me up, since C does inherit from P?
>
> Thanks
> Mohan K
>

Re: MultiModule and DependencyManagement?

Posted by Barrie Treloar <ba...@gmail.com>.
On Sun, Nov 30, 2008 at 9:50 AM, Mohan K R <km...@gmail.com> wrote:
> It appears that I'm missing something critical here, so please help me out.
> I have a standard
> multi-module project like this. (I'm using Maven 2.0.9, JDK5).
>
>  parent (P) -
>            |- module A
>            |- module B
>            |- module C
[del]
> NOTE: I do use log4j in B, but it got transitively pulled in. So far so
> good.

WARNING!

It is BAD practice to use a dependency that you do not declare.

If you are using log4j in module B, make sure that you declare it.

You can use dependency:analyze to show you where you may need to fix things up.
It doesn't work very well on the test scopes because there is no
equivalent of "runtime" for test.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: MultiModule and DependencyManagement?

Posted by "Walid \"jo\" Gedeon" <wg...@gmail.com>.
Yes, I would tend to agree that this noted cell should be 'runtime'.
The case where there's a dependency to a class (B) that extends one from
another library (C) makes my code compile dependent on that library (C). I
think my project needs to keep track of the version of library C to avoid
surprises when changes happen.
But others may disagree :-)

On Sun, Nov 30, 2008 at 1:24 AM, Mohan K R <km...@gmail.com> wrote:

> Thanks Walid. I think this is where my confusion is, the default scope is
> compile. And
> as per the matrix on the maven site it has an asterik describing the scope
> resolution.
> (for transitive dependencies)
>
> quote from docs: (
>
> http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
> )
>
> *(*) Note:* it is intended that this should be runtime scope instead, so
> that all compile dependencies must be explicitly listed - however, there is
> the case where the library you depend on extends a class from another
> library, forcing you to have available at compile time. For this reason,
> compile time dependencies remain as compile scope even when they are
> transitive.
>
> The above is the explanation for compile time dependency, as per above, it
> should not
> be runtime scope in C as you described or am I interpreting this wrong? It
> appears that
> if your explanation is right, then the doc should change that to runtime,
> at
> least that
> is what appears to be the behaviour in Maven 2.0.9.
>
>
> Thanks again
>
>
>
> On Sat, Nov 29, 2008 at 6:08 PM, Walid jo Gedeon <wg...@gmail.com>
> wrote:
>
> > Hello Mohan,
> >
> > In more technical jargon, log4j in your example is a compile time
> > dependency
> > of A, and only a runtime dependency of C, which means that if you want to
> > make log4j calls in C, you need to declare it as a compile time
> dependency
> > (default scope).
> >
> > HTH,
> > w
> >
> > On Sun, Nov 30, 2008 at 12:20 AM, Mohan K R <km...@gmail.com> wrote:
> >
> > > It appears that I'm missing something critical here, so please help me
> > out.
> > > I have a standard
> > > multi-module project like this. (I'm using Maven 2.0.9, JDK5).
> > >
> > >  parent (P) -
> > >            |- module A
> > >            |- module B
> > >            |- module C
> > >
> > >
> > > A,B,C all inherit from the parent P.
> > >
> > > Now in my parent POM (P): I have a dependencyManagement section in the
> > POM.
> > >  <depedencyManagement>
> > >    <dependencies>
> > >       <dependency>
> > >           <groupId>log4j</groupId>
> > >           <artifactId>log4j</artifactId>
> > >           <version>1.2.14</version>
> > >       <dependency>
> > >       <...  bunch of others ...>
> > >    <dependencies>
> > >  </dependencyManagement>
> > >
> > > Now in module A (I have a dependency on log4j), so only thing that I
> > > provide
> > > is (notice no version):
> > >
> > >    <dependencies>
> > >       <dependency>
> > >           <groupId>log4j</groupId>
> > >           <artifactId>log4j</artifactId>
> > >       <dependency>
> > >       <...  bunch of others ...>
> > >    <dependencies>
> > >
> > > Now in module B depends on module A so I have this in my dependency:
> > >    <dependencies>
> > >       <dependency>
> > >           <groupId>${project.groupId}</groupId>
> > >           <artifactId>module_A</artifactId> <!-- NOTICE MODULE A -->
> > >           <version>${project.version}</version>
> > >       <dependency>
> > >       <...  bunch of others ...*but no log4j*>
> > >    <dependencies>
> > > NOTE: I do use log4j in B, but it got transitively pulled in. So far so
> > > good.
> > >
> > > Now Module C, depends on Module B. So what I have is:
> > >    <dependencies>
> > >       <dependency>
> > >           <groupId>${project.groupId}</groupId>
> > >           <artifactId>module_B</artifactId>           <!-- NOTICE
> MODULE
> > B
> > > -->
> > >           <version>${project.version}</version>
> > >       <dependency>
> > >       <...  bunch of others ...>
> > >    <dependencies>
> > > Now, I do use some log4j calls (LogFactory), but for some reason log4j
> > does
> > > not
> > > get pulled in transitively??? I have to explicitly give a dependency on
> > > log4j *or*
> > > module_A to get it to compile??
> > >
> > > My first that was, all transitive dependencies on module_B should get
> > > pulled
> > > in which
> > > means module_A and in turn its transitive dependency log4j. But nothing
> > of
> > > this sort
> > > is happening? Any ideas? Is it the dependecyManagement section (which
> has
> > > the version)
> > > that is messing me up, since C does inherit from P?
> > >
> > > Thanks
> > > Mohan K
> > >
> >
>

Re: MultiModule and DependencyManagement?

Posted by Mohan K R <km...@gmail.com>.
Thanks Walid. I think this is where my confusion is, the default scope is
compile. And
as per the matrix on the maven site it has an asterik describing the scope
resolution.
(for transitive dependencies)

quote from docs: (
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
)

*(*) Note:* it is intended that this should be runtime scope instead, so
that all compile dependencies must be explicitly listed - however, there is
the case where the library you depend on extends a class from another
library, forcing you to have available at compile time. For this reason,
compile time dependencies remain as compile scope even when they are
transitive.

The above is the explanation for compile time dependency, as per above, it
should not
be runtime scope in C as you described or am I interpreting this wrong? It
appears that
if your explanation is right, then the doc should change that to runtime, at
least that
is what appears to be the behaviour in Maven 2.0.9.


Thanks again



On Sat, Nov 29, 2008 at 6:08 PM, Walid jo Gedeon <wg...@gmail.com> wrote:

> Hello Mohan,
>
> In more technical jargon, log4j in your example is a compile time
> dependency
> of A, and only a runtime dependency of C, which means that if you want to
> make log4j calls in C, you need to declare it as a compile time dependency
> (default scope).
>
> HTH,
> w
>
> On Sun, Nov 30, 2008 at 12:20 AM, Mohan K R <km...@gmail.com> wrote:
>
> > It appears that I'm missing something critical here, so please help me
> out.
> > I have a standard
> > multi-module project like this. (I'm using Maven 2.0.9, JDK5).
> >
> >  parent (P) -
> >            |- module A
> >            |- module B
> >            |- module C
> >
> >
> > A,B,C all inherit from the parent P.
> >
> > Now in my parent POM (P): I have a dependencyManagement section in the
> POM.
> >  <depedencyManagement>
> >    <dependencies>
> >       <dependency>
> >           <groupId>log4j</groupId>
> >           <artifactId>log4j</artifactId>
> >           <version>1.2.14</version>
> >       <dependency>
> >       <...  bunch of others ...>
> >    <dependencies>
> >  </dependencyManagement>
> >
> > Now in module A (I have a dependency on log4j), so only thing that I
> > provide
> > is (notice no version):
> >
> >    <dependencies>
> >       <dependency>
> >           <groupId>log4j</groupId>
> >           <artifactId>log4j</artifactId>
> >       <dependency>
> >       <...  bunch of others ...>
> >    <dependencies>
> >
> > Now in module B depends on module A so I have this in my dependency:
> >    <dependencies>
> >       <dependency>
> >           <groupId>${project.groupId}</groupId>
> >           <artifactId>module_A</artifactId> <!-- NOTICE MODULE A -->
> >           <version>${project.version}</version>
> >       <dependency>
> >       <...  bunch of others ...*but no log4j*>
> >    <dependencies>
> > NOTE: I do use log4j in B, but it got transitively pulled in. So far so
> > good.
> >
> > Now Module C, depends on Module B. So what I have is:
> >    <dependencies>
> >       <dependency>
> >           <groupId>${project.groupId}</groupId>
> >           <artifactId>module_B</artifactId>           <!-- NOTICE MODULE
> B
> > -->
> >           <version>${project.version}</version>
> >       <dependency>
> >       <...  bunch of others ...>
> >    <dependencies>
> > Now, I do use some log4j calls (LogFactory), but for some reason log4j
> does
> > not
> > get pulled in transitively??? I have to explicitly give a dependency on
> > log4j *or*
> > module_A to get it to compile??
> >
> > My first that was, all transitive dependencies on module_B should get
> > pulled
> > in which
> > means module_A and in turn its transitive dependency log4j. But nothing
> of
> > this sort
> > is happening? Any ideas? Is it the dependecyManagement section (which has
> > the version)
> > that is messing me up, since C does inherit from P?
> >
> > Thanks
> > Mohan K
> >
>

Re: MultiModule and DependencyManagement?

Posted by "Walid \"jo\" Gedeon" <wg...@gmail.com>.
Hello Mohan,

In more technical jargon, log4j in your example is a compile time dependency
of A, and only a runtime dependency of C, which means that if you want to
make log4j calls in C, you need to declare it as a compile time dependency
(default scope).

HTH,
w

On Sun, Nov 30, 2008 at 12:20 AM, Mohan K R <km...@gmail.com> wrote:

> It appears that I'm missing something critical here, so please help me out.
> I have a standard
> multi-module project like this. (I'm using Maven 2.0.9, JDK5).
>
>  parent (P) -
>            |- module A
>            |- module B
>            |- module C
>
>
> A,B,C all inherit from the parent P.
>
> Now in my parent POM (P): I have a dependencyManagement section in the POM.
>  <depedencyManagement>
>    <dependencies>
>       <dependency>
>           <groupId>log4j</groupId>
>           <artifactId>log4j</artifactId>
>           <version>1.2.14</version>
>       <dependency>
>       <...  bunch of others ...>
>    <dependencies>
>  </dependencyManagement>
>
> Now in module A (I have a dependency on log4j), so only thing that I
> provide
> is (notice no version):
>
>    <dependencies>
>       <dependency>
>           <groupId>log4j</groupId>
>           <artifactId>log4j</artifactId>
>       <dependency>
>       <...  bunch of others ...>
>    <dependencies>
>
> Now in module B depends on module A so I have this in my dependency:
>    <dependencies>
>       <dependency>
>           <groupId>${project.groupId}</groupId>
>           <artifactId>module_A</artifactId> <!-- NOTICE MODULE A -->
>           <version>${project.version}</version>
>       <dependency>
>       <...  bunch of others ...*but no log4j*>
>    <dependencies>
> NOTE: I do use log4j in B, but it got transitively pulled in. So far so
> good.
>
> Now Module C, depends on Module B. So what I have is:
>    <dependencies>
>       <dependency>
>           <groupId>${project.groupId}</groupId>
>           <artifactId>module_B</artifactId>           <!-- NOTICE MODULE B
> -->
>           <version>${project.version}</version>
>       <dependency>
>       <...  bunch of others ...>
>    <dependencies>
> Now, I do use some log4j calls (LogFactory), but for some reason log4j does
> not
> get pulled in transitively??? I have to explicitly give a dependency on
> log4j *or*
> module_A to get it to compile??
>
> My first that was, all transitive dependencies on module_B should get
> pulled
> in which
> means module_A and in turn its transitive dependency log4j. But nothing of
> this sort
> is happening? Any ideas? Is it the dependecyManagement section (which has
> the version)
> that is messing me up, since C does inherit from P?
>
> Thanks
> Mohan K
>