views:

99

answers:

1

Hi all,

I make use of dependency POMs which I will then go and include into another projects as as dependency. The problem I am having is while it aggregates the POM with those dependencies, it appears when I declare dependencies of scope, provided, those aren't included.

Is it possible to include provided dependencies in dependency POMs with a scope of provided? I often declare what APIs I need and then include the implementation as a runtime dependency.

Walter

+3  A: 

If a dependency is provided why can't that dependency be inherited with the same scope so I don't have to declare it?

It is inherited with the same scope. Given the following parent pom.xml:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.stackoverflow.Q3597684</groupId>
  <artifactId>root</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>Q3597684 - Root</name>
  <packaging>pom</packaging>
  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

And the following pom.xml that inherits from the root artifact:

<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>root</artifactId>
    <groupId>com.stackoverflow.Q3597684</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <artifactId>child</artifactId>
  <packaging>war</packaging>
  <name>Q3597684 - Child</name>
  <dependencies/>
</project>

Running mvn dependency:tree from the child gives the following output:

$ mvn dependency:tree[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3597684 - Child
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] com.stackoverflow.Q3597684:child:war:1.0-SNAPSHOT
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] \- junit:junit:jar:3.8.1:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------

The provided servlet-api is there, as expected.

Are you maybe (mis)using the dependencyManagement section?

Pascal Thivent
I don't declare my modules <modules><module>child</module</modules>. I don't do it that way because I would only know of internal children and not external projects.
@Walter This is not important (my parent pom is an aggregating pom because I used archetypes to setup this project), the important part is the `<parent>` element. You can use inheritance without aggregation, and this doesn't change my answer. But I'll update it to show inheritance only and avoid any confusion.
Pascal Thivent