You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by James Carman <ja...@carmanconsulting.com> on 2008/02/16 20:05:07 UTC

Dependencies...

What is the "maven way" of doing this?  Suppose a library you're
writing requires Spring.  You write your library against an older
version of Spring (2.0) and you define it as a dependency.  Now, when
other projects want to use your library, spring-2.0.jar will be
included in their classpath as a transitive dependency.  But, what if
the project wants to use Spring 2.5.1?  They would have to do an
exclusion on their dependency to tell it not to include the
spring-2.0.jar, right?  What scope should the library put on the
spring dependency so that any projects using that library can provide
their own version of spring?

James

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


Re: Dependencies...

Posted by "simon.kitching@chello.at" <si...@chello.at>.
I'm not sure what either of you mean here.

Normally, your lib's pom just declares a dependency on the "recommended"
version of the lib you want (Spring in this case), eg
  <version>2.0.4</version>

When a project depends on your lib but doesn't otherwise use Spring,
then your "recommended" version is used. If the project does use Spring
itself, then the version it specifies overrides the one that your pom
specifies. This overriding happens automatically; the version *closest
to the pom being built* always has priority.

If your library is known not to work with certain spring versions (eg
cannot work with Spring <1.5 and cannot work with spring 2.0 or later)
then your lib's pom should use a version-range to indicate that. Then if
anyone's pom has a direct Spring dependency that is incompatible with
that range then an error is displayed - but otherwise their version has
priority.

I don't know what version you get when a pom specifies a range and
nothing overrides it; probably the lower-bound of the range is used as
that is the "stable" (repeatable) option.

And all of this applies to dependencies of any scope. Scope of
"provided" has other implications..

Regards,
Simon

Stephen Connolly schrieb:
> <scope>provided</scope>
>
> On Feb 16, 2008 7:05 PM, James Carman <ja...@carmanconsulting.com> wrote:
>
>   
>> What is the "maven way" of doing this?  Suppose a library you're
>> writing requires Spring.  You write your library against an older
>> version of Spring (2.0) and you define it as a dependency.  Now, when
>> other projects want to use your library, spring-2.0.jar will be
>> included in their classpath as a transitive dependency.  But, what if
>> the project wants to use Spring 2.5.1?  They would have to do an
>> exclusion on their dependency to tell it not to include the
>> spring-2.0.jar, right?  What scope should the library put on the
>> spring dependency so that any projects using that library can provide
>> their own version of spring?
>>
>> James
>>
>> ---------------------------------------------------------------------
>> 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: Dependencies...

Posted by Stephen Connolly <st...@gmail.com>.
<scope>provided</scope>

On Feb 16, 2008 7:05 PM, James Carman <ja...@carmanconsulting.com> wrote:

> What is the "maven way" of doing this?  Suppose a library you're
> writing requires Spring.  You write your library against an older
> version of Spring (2.0) and you define it as a dependency.  Now, when
> other projects want to use your library, spring-2.0.jar will be
> included in their classpath as a transitive dependency.  But, what if
> the project wants to use Spring 2.5.1?  They would have to do an
> exclusion on their dependency to tell it not to include the
> spring-2.0.jar, right?  What scope should the library put on the
> spring dependency so that any projects using that library can provide
> their own version of spring?
>
> James
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Dependencies...

Posted by Andrius Ĺ abanas <an...@pivotcapital.com>.
James Carman wrote:
> What is the "maven way" of doing this?  Suppose a library you're
> writing requires Spring.  You write your library against an older
> version of Spring (2.0) and you define it as a dependency.  Now, when
> other projects want to use your library, spring-2.0.jar will be
> included in their classpath as a transitive dependency.  But, what if
> the project wants to use Spring 2.5.1?  They would have to do an
> exclusion on their dependency to tell it not to include the
> spring-2.0.jar, right?  What scope should the library put on the
> spring dependency so that any projects using that library can provide
> their own version of spring?

Generally you do not need to do anything special with your dependency, 
because if the project using your library explicitly declares Spring 
dependency in <dependencies> or <dependencyManagement>, it will override 
the transitive version.

However, Spring case is a bit specific as it comes in two flavors - 
single monolithic spring-{version}.jar or a set of 
spring-{component}-{version}.jar. Spring developers advocate the use of 
specific component jars, IMHO, so in that case it would probably be best 
to denote dependency to Spring as <optional>true</optional>, thus not 
transitively included, as any project using Spring would have explicit 
dependencies anyway.

Regarding using <scope>provided</scope> - I do not think it is a good 
idea, as this dependency would still be included during compilation and 
testing phases, and could cause strange conflicts. "Provided" scope 
should only be used to exclude the jar from being packaged within WAR, 
etc... - mostly used for things like servlet-api or JCE providers.


cheers,

Andrius

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