Maven-依赖关系继承-提供 [英] Maven - Dependency Inheritance - Provided

查看:99
本文介绍了Maven-依赖关系继承-提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我利用依赖项POM,然后将其作为依赖项并包含在另一个项目中.我遇到的问题是,它将POM与那些依赖项聚合在一起时,当我声明范围的依赖项(如果不包含这些依赖项)时,就会出现该问题.

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.

是否可以在提供范围内将提供的依赖项包含在依赖项POM中?我经常声明我需要什么API,然后将实现作为运行时依赖项包含在内.

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.

推荐答案

如果提供了依赖项,为什么不能在相同范围内继承该依赖项,所以我不必声明它?

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

,具有相同的作用域.给定以下父级pom.xml:

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>

以及以下从根工件继承的pom.xml:

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>

从子级运行mvn dependency:tree会给出以下输出:

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] ------------------------------------------------------------------------

提供的servlet-api在那里,如预期的那样.

The provided servlet-api is there, as expected.

您是否可能(mis)使用dependencyManagement部分?

Are you maybe (mis)using the dependencyManagement section?

这篇关于Maven-依赖关系继承-提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆