You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Graham Crosmarie <gr...@linagora.com> on 2012/07/17 09:15:05 UTC

Duplicate dependency with different scopes

Hello,

I have a problem with my dependency pattern and I am not sure that maven 
behaves correctly in this case.

Here is my case :
     - I am using Maven 2.2.1.
     - I have a project A which defines a dependency D with scope test.
     - I have a project B whose parent is A and which defines D as a 
dependency in scope compile.
     - My project hierarchy defines a lot of projects whose parent is A 
and who have B as a dependency.

My problem is : all these "subprojects" have D as dependency in scope 
test (from A).
I think that the correct behaviour would be to have D with scope compile 
(from their dependency on B) because scope compile 'contains' scope 
test. But Maven 2.2.1 does not work that way :-).

Is there any way to force my projects to use the D scope from project B 
instead of the one from its parent (project A) ?

Thanks in avance,

-- 
Signature
Graham CROSMARIE
R&D Engineer
Linagora GSO -- www.linagora.com <http://www.linagora.com>

Re: Duplicate dependency with different scopes

Posted by Jörg Schaible <Jo...@scalaris.com>.
Hi Graham,

Graham Crosmarie wrote:

> Thanks for your answer,
> 
> But somehow I disagree with you : a pom project might have to define
> dependencies.
> IMHO defining such a dependency (besides defining its version and scope
> in the dependency management) is legitimate if all of the projects
> having this pom as parent should have this dependency.
> 
> For example our parent pom which is the parent of all our other projects
> defines Junit as a dependency because we know all of our prejects are
> going to use Junit.
> 
> In my case all subprojects of A need D at least in scope test but some
> of them (which depends on B) appears to 'also' need D in scope compile.

well, Maven gives you, what you have defined. If you define D for all 
projects directly as scope test, why do you complain at all?

- Jörg


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


Re: Duplicate dependency with different scopes

Posted by Anders Hammar <an...@hammar.net>.
Well, I disagree with you. A pom project doesn't have a dependency. It
doesn't have any code and thus no dependencies.

Also, based on my experience, there will always be exceptions to the
rule "all children will have this dependency". A very common one is
thinking that all children will have a junit test dependency. Sounds
reasonable in the beginning, but what happens when you have an API
module? This one is very unlikely to have any tests as it only
includes interfaces (or possibly very simple classes). And then it
will get an incorrect dependency. Sure, an extra test scope dependency
will not affect any project having a dependency, but this is still an
incorrect dependency.

/Anders

On Tue, Jul 17, 2012 at 10:57 AM, Graham Crosmarie
<gr...@linagora.com> wrote:
> Thanks for your answer,
>
> But somehow I disagree with you : a pom project might have to define
> dependencies.
> IMHO defining such a dependency (besides defining its version and scope in
> the dependency management) is legitimate if all of the projects having this
> pom as parent should have this dependency.
>
> For example our parent pom which is the parent of all our other projects
> defines Junit as a dependency because we know all of our prejects are going
> to use Junit.
>
> In my case all subprojects of A need D at least in scope test but some of
> them (which depends on B) appears to 'also' need D in scope compile.
>
>
> On 17/07/2012 09:43, Anders Hammar wrote:
>>
>> As project A is a parent it's a pom project, right? IMHO a pom project
>> should NEVER have a dependency. Remove that dependency and state that
>> test scope dependency where it actually is a dependency instead.
>> Project A could however have dependencyManagement declared for D
>> stating test as default scope (and version).
>>
>> /Anders
>>
>> On Tue, Jul 17, 2012 at 9:15 AM, Graham Crosmarie
>> <gr...@linagora.com> wrote:
>>>
>>> Hello,
>>>
>>> I have a problem with my dependency pattern and I am not sure that maven
>>> behaves correctly in this case.
>>>
>>> Here is my case :
>>>      - I am using Maven 2.2.1.
>>>      - I have a project A which defines a dependency D with scope test.
>>>      - I have a project B whose parent is A and which defines D as a
>>> dependency in scope compile.
>>>      - My project hierarchy defines a lot of projects whose parent is A
>>> and
>>> who have B as a dependency.
>>>
>>> My problem is : all these "subprojects" have D as dependency in scope
>>> test
>>> (from A).
>>> I think that the correct behaviour would be to have D with scope compile
>>> (from their dependency on B) because scope compile 'contains' scope test.
>>> But Maven 2.2.1 does not work that way :-).
>>>
>>> Is there any way to force my projects to use the D scope from project B
>>> instead of the one from its parent (project A) ?
>>>
>>> Thanks in avance,
>>>
>>> --
>>> Signature
>>> Graham CROSMARIE
>>> R&D Engineer
>>> Linagora GSO -- www.linagora.com <http://www.linagora.com>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>
>
> --
> Signature
> Graham CROSMARIE
> R&D Engineer
> Linagora GSO -- www.linagora.com <http://www.linagora.com>

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


Re: Duplicate dependency with different scopes

Posted by Graham Crosmarie <gr...@linagora.com>.
Thanks for your answer,

But somehow I disagree with you : a pom project might have to define 
dependencies.
IMHO defining such a dependency (besides defining its version and scope 
in the dependency management) is legitimate if all of the projects 
having this pom as parent should have this dependency.

For example our parent pom which is the parent of all our other projects 
defines Junit as a dependency because we know all of our prejects are 
going to use Junit.

In my case all subprojects of A need D at least in scope test but some 
of them (which depends on B) appears to 'also' need D in scope compile.


On 17/07/2012 09:43, Anders Hammar wrote:
> As project A is a parent it's a pom project, right? IMHO a pom project
> should NEVER have a dependency. Remove that dependency and state that
> test scope dependency where it actually is a dependency instead.
> Project A could however have dependencyManagement declared for D
> stating test as default scope (and version).
>
> /Anders
>
> On Tue, Jul 17, 2012 at 9:15 AM, Graham Crosmarie
> <gr...@linagora.com> wrote:
>> Hello,
>>
>> I have a problem with my dependency pattern and I am not sure that maven
>> behaves correctly in this case.
>>
>> Here is my case :
>>      - I am using Maven 2.2.1.
>>      - I have a project A which defines a dependency D with scope test.
>>      - I have a project B whose parent is A and which defines D as a
>> dependency in scope compile.
>>      - My project hierarchy defines a lot of projects whose parent is A and
>> who have B as a dependency.
>>
>> My problem is : all these "subprojects" have D as dependency in scope test
>> (from A).
>> I think that the correct behaviour would be to have D with scope compile
>> (from their dependency on B) because scope compile 'contains' scope test.
>> But Maven 2.2.1 does not work that way :-).
>>
>> Is there any way to force my projects to use the D scope from project B
>> instead of the one from its parent (project A) ?
>>
>> Thanks in avance,
>>
>> --
>> Signature
>> Graham CROSMARIE
>> R&D Engineer
>> Linagora GSO -- www.linagora.com <http://www.linagora.com>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>


-- 
Signature
Graham CROSMARIE
R&D Engineer
Linagora GSO -- www.linagora.com <http://www.linagora.com>

Re: Duplicate dependency with different scopes

Posted by Anders Hammar <an...@hammar.net>.
As project A is a parent it's a pom project, right? IMHO a pom project
should NEVER have a dependency. Remove that dependency and state that
test scope dependency where it actually is a dependency instead.
Project A could however have dependencyManagement declared for D
stating test as default scope (and version).

/Anders

On Tue, Jul 17, 2012 at 9:15 AM, Graham Crosmarie
<gr...@linagora.com> wrote:
> Hello,
>
> I have a problem with my dependency pattern and I am not sure that maven
> behaves correctly in this case.
>
> Here is my case :
>     - I am using Maven 2.2.1.
>     - I have a project A which defines a dependency D with scope test.
>     - I have a project B whose parent is A and which defines D as a
> dependency in scope compile.
>     - My project hierarchy defines a lot of projects whose parent is A and
> who have B as a dependency.
>
> My problem is : all these "subprojects" have D as dependency in scope test
> (from A).
> I think that the correct behaviour would be to have D with scope compile
> (from their dependency on B) because scope compile 'contains' scope test.
> But Maven 2.2.1 does not work that way :-).
>
> Is there any way to force my projects to use the D scope from project B
> instead of the one from its parent (project A) ?
>
> Thanks in avance,
>
> --
> Signature
> Graham CROSMARIE
> R&D Engineer
> Linagora GSO -- www.linagora.com <http://www.linagora.com>

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


Re: Duplicate dependency with different scopes

Posted by Anders Hammar <an...@hammar.net>.
I believe what happens here is that the dependency declared closest to
your project wins. But you can control this through
dependencyManagement in your project.

/Anders

On Tue, Jul 17, 2012 at 5:06 PM, Graham Crosmarie
<gr...@linagora.com> wrote:
> A defines a dependency on D with scope test and is a pom project
>
> B defines a dependency on D with compile (default) and is a jar project.
> A is the parent pom of B.
> When I run dependency:tree I get what I want for B : D with scope compile.
>
> I have other projects (C) whose parent is A and which depend on B with scope
> compile(default).
> My problem is that the D dependency for such projects is in scope test
> (inherited from A) instead of scope compile (retrieved through the
> dependency on B).
>
> In other words Maven chooses the wrong scope for my C projects. In fact, I
> think it always takes the one from the before parent and ignores the one
> from the dependency.
>
>
> On 17/07/2012 15:29, Aliaksei Lahachou wrote:
>>
>> Hi!
>>
>> In parent A, so you define scope in dependency or dependency management
>> section. If the latter, then it overrides scope of the transitive
>> dependency.
>>
>> In which scope is dependency B? If it's in test scope, than its
>> dependencies will be in test scope, too.
>>
>> It would be much easier if you could show the POMs.
>>
>> Regards,
>> htfv (Aliaksei Lahachou)
>> Am 17.07.2012 09:15 schrieb "Graham Crosmarie" <
>> graham.crosmarie@linagora.com>:
>>
>>> Hello,
>>>
>>> I have a problem with my dependency pattern and I am not sure that maven
>>> behaves correctly in this case.
>>>
>>> Here is my case :
>>>      - I am using Maven 2.2.1.
>>>      - I have a project A which defines a dependency D with scope test.
>>>      - I have a project B whose parent is A and which defines D as a
>>> dependency in scope compile.
>>>      - My project hierarchy defines a lot of projects whose parent is A
>>> and
>>> who have B as a dependency.
>>>
>>> My problem is : all these "subprojects" have D as dependency in scope
>>> test
>>> (from A).
>>> I think that the correct behaviour would be to have D with scope compile
>>> (from their dependency on B) because scope compile 'contains' scope test.
>>> But Maven 2.2.1 does not work that way :-).
>>>
>>> Is there any way to force my projects to use the D scope from project B
>>> instead of the one from its parent (project A) ?
>>>
>>> Thanks in avance,
>>>
>>> --
>>> Signature
>>> Graham CROSMARIE
>>> R&D Engineer
>>> Linagora GSO -- www.linagora.com <http://www.linagora.com>
>>>
>
>
> --
> Signature
> Graham CROSMARIE
> R&D Engineer
> Linagora GSO -- www.linagora.com <http://www.linagora.com>

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


Re: Duplicate dependency with different scopes

Posted by Graham Crosmarie <gr...@linagora.com>.
A defines a dependency on D with scope test and is a pom project

B defines a dependency on D with compile (default) and is a jar project.
A is the parent pom of B.
When I run dependency:tree I get what I want for B : D with scope compile.

I have other projects (C) whose parent is A and which depend on B with scope compile(default).
My problem is that the D dependency for such projects is in scope test (inherited from A) instead of scope compile (retrieved through the dependency on B).

In other words Maven chooses the wrong scope for my C projects. In fact, I think it always takes the one from the before parent and ignores the one from the dependency.


On 17/07/2012 15:29, Aliaksei Lahachou wrote:
> Hi!
>
> In parent A, so you define scope in dependency or dependency management
> section. If the latter, then it overrides scope of the transitive
> dependency.
>
> In which scope is dependency B? If it's in test scope, than its
> dependencies will be in test scope, too.
>
> It would be much easier if you could show the POMs.
>
> Regards,
> htfv (Aliaksei Lahachou)
> Am 17.07.2012 09:15 schrieb "Graham Crosmarie" <
> graham.crosmarie@linagora.com>:
>
>> Hello,
>>
>> I have a problem with my dependency pattern and I am not sure that maven
>> behaves correctly in this case.
>>
>> Here is my case :
>>      - I am using Maven 2.2.1.
>>      - I have a project A which defines a dependency D with scope test.
>>      - I have a project B whose parent is A and which defines D as a
>> dependency in scope compile.
>>      - My project hierarchy defines a lot of projects whose parent is A and
>> who have B as a dependency.
>>
>> My problem is : all these "subprojects" have D as dependency in scope test
>> (from A).
>> I think that the correct behaviour would be to have D with scope compile
>> (from their dependency on B) because scope compile 'contains' scope test.
>> But Maven 2.2.1 does not work that way :-).
>>
>> Is there any way to force my projects to use the D scope from project B
>> instead of the one from its parent (project A) ?
>>
>> Thanks in avance,
>>
>> --
>> Signature
>> Graham CROSMARIE
>> R&D Engineer
>> Linagora GSO -- www.linagora.com <http://www.linagora.com>
>>


-- 
Signature
Graham CROSMARIE
R&D Engineer
Linagora GSO -- www.linagora.com <http://www.linagora.com>

Re: Duplicate dependency with different scopes

Posted by Aliaksei Lahachou <al...@gmail.com>.
Hi!

In parent A, so you define scope in dependency or dependency management
section. If the latter, then it overrides scope of the transitive
dependency.

In which scope is dependency B? If it's in test scope, than its
dependencies will be in test scope, too.

It would be much easier if you could show the POMs.

Regards,
htfv (Aliaksei Lahachou)
Am 17.07.2012 09:15 schrieb "Graham Crosmarie" <
graham.crosmarie@linagora.com>:

> Hello,
>
> I have a problem with my dependency pattern and I am not sure that maven
> behaves correctly in this case.
>
> Here is my case :
>     - I am using Maven 2.2.1.
>     - I have a project A which defines a dependency D with scope test.
>     - I have a project B whose parent is A and which defines D as a
> dependency in scope compile.
>     - My project hierarchy defines a lot of projects whose parent is A and
> who have B as a dependency.
>
> My problem is : all these "subprojects" have D as dependency in scope test
> (from A).
> I think that the correct behaviour would be to have D with scope compile
> (from their dependency on B) because scope compile 'contains' scope test.
> But Maven 2.2.1 does not work that way :-).
>
> Is there any way to force my projects to use the D scope from project B
> instead of the one from its parent (project A) ?
>
> Thanks in avance,
>
> --
> Signature
> Graham CROSMARIE
> R&D Engineer
> Linagora GSO -- www.linagora.com <http://www.linagora.com>
>