You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Mickael Marrache <Mi...@xconnect.net> on 2012/01/19 11:37:27 UTC

Dependency scope precedence?

Hi,

I have a project A that uses library L v1.0.0 with test scope.

Project A also depends on project B (with scope compile), with B transitively depending on the library L v1.0.0 (with scope compile). So, according to the documentation (Introduction to dependency mechanism), project A depends on project B with scope "compile" and the transitive dependency on L has a "compile" scope, the final scope of L should be "compile".

Here, Maven sees one dependency on L with scope "compile" (after applying the dependency algorithm), and one dependency on L with scope "test". Why the final scope of the library L for project A is 'test'? It seems that the dependency definition of project A on library L overrides those of the transitive dependencies on L.

It causes me NotClassDefFoundError at runtime.

What's wrong here? My project A only uses L for unit tests so I define the dependency with 'test' scope. But, at the end, I want L to be on my classpath since project A depends on project B for production, and B needs (transitively) library L also for production. (By production, I mean not unit tests.)

Thanks for helping me


Re: Dependency scope precedence?

Posted by Ron Wheeler <rw...@artifact-software.com>.
It appears that the second solution will get you what you want and make 
it much more explicit so that when/if you remove B, you will see the 
dependency on L and just have to change its scope.

I am not too excited about extra libraries in production since they are 
only loaded when required and most are small.
If it is a huge library, you would want to be more careful.

I am a little surprised that Maven would not include L in the production 
artifact.
We manage dependencies very tightly and would have set up our POM as 
suggested in 2 and not worried about the "test" scope since L is always 
there (in your current case).

You might want to file a bug report and see what the developers say or 
do about this.
There is not much that you can do in the user forum can do to resolve 
this properly but you seem to have a workaround pretty well under control.

Ron


On 19/01/2012 9:37 AM, Mickael Marrache wrote:
> On the contrary, I would need the dependency on L with compile scope.
>
> The first solution you propose ( a) ) is what I use for now, but I don't understand why Maven can't decide that here the final scope has to be compile and not test. This solution seems to be temporary and by removing the dependency, you lose trace in your POM that you also use L directly from project A, and if in the future, you decide to remove the dependency of project A on project B, you'll need to add the test-scoped dependency on L in the POM of project A. This is the same for the second solution, if you remove the dependency on B in the future, you'll get the L library in your classpath (even for production).
>
> Am I right or missing something here? Do you think it can be added as a "new feature"?
>
> Mickael
>
> -----Original Message-----
> From: Ron Wheeler [mailto:rwheeler@artifact-software.com]
> Sent: Thursday, January 19, 2012 4:28 PM
> To: Maven Users List
> Subject: Re: Dependency scope precedence?
>
>
> Not sure why you would need the dependency on L with test scope.
>
> It appears that project A always has project B which always needs L.
>
> L has to be there regardless of whether you are in test or production.
> It appears that you could just
> a)remove the reference from A to L or
> b) make it compile if you want and exclude it from A's dependency on B
> if you want to control the version in project A
>
>
> Am I misreading your description?
>
> Ron
>
> On 19/01/2012 5:37 AM, Mickael Marrache wrote:
>> Hi,
>>
>> I have a project A that uses library L v1.0.0 with test scope.
>>
>> Project A also depends on project B (with scope compile), with B transitively depending on the library L v1.0.0 (with scope compile). So, according to the documentation (Introduction to dependency mechanism), project A depends on project B with scope "compile" and the transitive dependency on L has a "compile" scope, the final scope of L should be "compile".
>>
>> Here, Maven sees one dependency on L with scope "compile" (after applying the dependency algorithm), and one dependency on L with scope "test". Why the final scope of the library L for project A is 'test'? It seems that the dependency definition of project A on library L overrides those of the transitive dependencies on L.
>>
>> It causes me NotClassDefFoundError at runtime.
>>
>> What's wrong here? My project A only uses L for unit tests so I define the dependency with 'test' scope. But, at the end, I want L to be on my classpath since project A depends on project B for production, and B needs (transitively) library L also for production. (By production, I mean not unit tests.)
>>
>> Thanks for helping me
>>
>>
>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102



RE: Dependency scope precedence?

Posted by Mickael Marrache <Mi...@xconnect.net>.
On the contrary, I would need the dependency on L with compile scope.

The first solution you propose ( a) ) is what I use for now, but I don't understand why Maven can't decide that here the final scope has to be compile and not test. This solution seems to be temporary and by removing the dependency, you lose trace in your POM that you also use L directly from project A, and if in the future, you decide to remove the dependency of project A on project B, you'll need to add the test-scoped dependency on L in the POM of project A. This is the same for the second solution, if you remove the dependency on B in the future, you'll get the L library in your classpath (even for production).

Am I right or missing something here? Do you think it can be added as a "new feature"?

Mickael

-----Original Message-----
From: Ron Wheeler [mailto:rwheeler@artifact-software.com] 
Sent: Thursday, January 19, 2012 4:28 PM
To: Maven Users List
Subject: Re: Dependency scope precedence?


Not sure why you would need the dependency on L with test scope.

It appears that project A always has project B which always needs L.

L has to be there regardless of whether you are in test or production.
It appears that you could just
a)remove the reference from A to L or
b) make it compile if you want and exclude it from A's dependency on B 
if you want to control the version in project A


Am I misreading your description?

Ron

On 19/01/2012 5:37 AM, Mickael Marrache wrote:
> Hi,
>
> I have a project A that uses library L v1.0.0 with test scope.
>
> Project A also depends on project B (with scope compile), with B transitively depending on the library L v1.0.0 (with scope compile). So, according to the documentation (Introduction to dependency mechanism), project A depends on project B with scope "compile" and the transitive dependency on L has a "compile" scope, the final scope of L should be "compile".
>
> Here, Maven sees one dependency on L with scope "compile" (after applying the dependency algorithm), and one dependency on L with scope "test". Why the final scope of the library L for project A is 'test'? It seems that the dependency definition of project A on library L overrides those of the transitive dependencies on L.
>
> It causes me NotClassDefFoundError at runtime.
>
> What's wrong here? My project A only uses L for unit tests so I define the dependency with 'test' scope. But, at the end, I want L to be on my classpath since project A depends on project B for production, and B needs (transitively) library L also for production. (By production, I mean not unit tests.)
>
> Thanks for helping me
>
>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102



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


Re: Dependency scope precedence?

Posted by Ron Wheeler <rw...@artifact-software.com>.
Not sure why you would need the dependency on L with test scope.

It appears that project A always has project B which always needs L.

L has to be there regardless of whether you are in test or production.
It appears that you could just
a)remove the reference from A to L or
b) make it compile if you want and exclude it from A's dependency on B 
if you want to control the version in project A


Am I misreading your description?

Ron

On 19/01/2012 5:37 AM, Mickael Marrache wrote:
> Hi,
>
> I have a project A that uses library L v1.0.0 with test scope.
>
> Project A also depends on project B (with scope compile), with B transitively depending on the library L v1.0.0 (with scope compile). So, according to the documentation (Introduction to dependency mechanism), project A depends on project B with scope "compile" and the transitive dependency on L has a "compile" scope, the final scope of L should be "compile".
>
> Here, Maven sees one dependency on L with scope "compile" (after applying the dependency algorithm), and one dependency on L with scope "test". Why the final scope of the library L for project A is 'test'? It seems that the dependency definition of project A on library L overrides those of the transitive dependencies on L.
>
> It causes me NotClassDefFoundError at runtime.
>
> What's wrong here? My project A only uses L for unit tests so I define the dependency with 'test' scope. But, at the end, I want L to be on my classpath since project A depends on project B for production, and B needs (transitively) library L also for production. (By production, I mean not unit tests.)
>
> Thanks for helping me
>
>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102



RE: Dependency scope precedence?

Posted by Mickael Marrache <Mi...@xconnect.net>.
I understand that we need to find a solution when there is a conflict between different versions of the same artifact. In this case, the nearest-strategy is used. But, concerning the scope, why someone would need to override scope of an artifact? If I declare that A compile-dep on B, and I also declare that B compile-dep on L, that's because B needs L for production. Now, A also uses L for unit tests, so I declare that A test-dep on L. Why thinking of overriding the scope of L? In this case, we have the same dependency twice (note that the two dependencies correspond to the same artifact - same version), on one hand, I need L for production, on another hand, I need L for unit tests only, I think that there should be a priority between scopes, so we can make a choice. Choosing a scope test for L in this example is a bad idea (I think), because now I get an error message at runtime or even compilation. And now, I need to check all my projects to look if this special case appears and if yes, to use one of the previous 'workaround'.

Maybe I'm missing something, maybe there is another issue (maybe more important) in the other side.

Mickael

-----Original Message-----
From: Wayne Fay [mailto:waynefay@gmail.com] 
Sent: Thursday, January 19, 2012 5:38 PM
To: Maven Users List
Subject: Re: Dependency scope precedence?

> What's wrong here? My project A only uses L for unit tests so I define the dependency with
> 'test' scope. But, at the end, I want L to be on my classpath since project A depends on
> project B for production, and B needs (transitively) library L also for production. (By production,

OK so in a nutshell...
A compile-dep B
A test-dep L
B compile-dep L

Because A has a test-dep to L, that overrides the B compile-dep on L
which is brought in to A transitively. You are effectively downgrading
the scope of this library by declaring it locally as a test
dependency.

What kind of package are you building?

Wayne

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


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


Re: Dependency scope precedence?

Posted by Wayne Fay <wa...@gmail.com>.
> What's wrong here? My project A only uses L for unit tests so I define the dependency with
> 'test' scope. But, at the end, I want L to be on my classpath since project A depends on
> project B for production, and B needs (transitively) library L also for production. (By production,

OK so in a nutshell...
A compile-dep B
A test-dep L
B compile-dep L

Because A has a test-dep to L, that overrides the B compile-dep on L
which is brought in to A transitively. You are effectively downgrading
the scope of this library by declaring it locally as a test
dependency.

What kind of package are you building?

Wayne

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