maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jörg Schaible <Joerg.Schai...@scalaris.com>
Subject Re: Provided scope dependencies
Date Fri, 15 Mar 2013 08:51:32 GMT
Hi Patrick,

Patrick Schlebusch wrote:

> Thanks, this is exactly what I was getting at.
> 
> As this higher-level project does not reference javax.mail:mail in any
> way, it should not have to specify a direct dependency on it imho.
> Yet in the current state of things it needs to, but only in the special
> case that the provided scope is used by the primordial project.
> 
> While this might all sound a bit abstract, we actually run into these
> problems when working with OSGi bundles (which is mentioned as an affected
> use case in the JIRA as well).
> The provided scope fits pretty nicely for bundles, since we do not want to
> package these dependencies but need to compile against them.
> 
> I guess I just don't see why it would be a good thing to not provide
> compile-time dependencies transitively. I thought that was one of the core
> ideas of Maven?

in the end, you always control it yourself (that's what project parents and 
dependencyManagement sections are for) and in combination with properties 
you have absolute control.

Parent POM for a project:

============ %< =============
<groupId>our.company</groupId>
<artifactId>project-master</artifactId>
<version>1.x-SNASPHTO</version>
...
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>javax.mail</groupId>
      <artifactId>mail</artifactId>
      <version>1.4</version>
      <scope>${scope.javax.mail}</scope>
    <dependency>
  </dependencies>
</dependencyManagement>
...
<properties>
  <!-- scope defaults, even for transitive deps -->
  <scope.javax.mail>compile</scope.javax.mail>
</properties>
============ %< =============


In an artifact of the project that should not include this dependency, e.g. 
for an EAR or WAR:

============ %< =============
<parent>
  <groupId>our.company</groupId>
  <artifactId>project-master</artifactId>
  <version>1.x-SNASPHTO</version>
  <relativePath/> <!-- is not necessarily physical parent! -->
</parent>
...
<properties>
  <scope.javax.mail>provided</scope.javax.mail>
</properties>
============ %< =============

Now, if all artifacts of a project refer the same parent (directly or 
indirectly), you can overwite the scope (and version) of any dependency used 
anywhere in this project with that single declaration in the depMgmt section 
of the parent with own defaults that can be overwritten in the POMs of the 
individual artifacts.

Cheers,
Jörg


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


Mime
View raw message