我提到了依赖管理和maven中的依赖之间的线程差异,但是这个问题是特定的。

父POM:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.company.rtdp.rtds</groupId>
      <artifactId>rtds-client</artifactId>
      <version>${rtdp.rtds-client.version}</version>
      <!-- SCENARIO 1 : Either give scope here in parent POM -->
      <!-- <scope>provided</scope> -->
    </dependency>
  </dependencies>
</dependencyManagement>

<rtdp.rtds-client.version>1.4.6</rtdp.rtds-client.version>

子POM:

 <dependencies>
    <!-- SCENARIO 2
    <dependency> 
        <groupId>com.company.rtdp.rtds</groupId> 
        <artifactId>realtimedataserv-client</artifactId> 
        <version>1.4.6</version>
        <scope>provided</scope> 
    </dependency> 
    -->

    <dependency> 
        <groupId>com.company.idi</groupId> 
        <artifactId>idi-persistence</artifactId>
        <version>3.3</version>
        <!--  has a dependency of com.company.rtdp.rtds:rtds-client:jar:1.4.6:compile -->
    </dependency>
 </dependencies>

<!-- SCENARIO 1: OR give scope here in child POM 
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.company.rtdp.rtds</groupId>
      <artifactId>rtds-client</artifactId>
      <version>1.4.6</version>
      <scope>provided</scope> 
    </dependency>
  </dependencies>
</dependencyManagement>
-->

rtds-client是许多工件的传递依赖,其中idi-persistence是其中之一。 我想在所有传递性依赖项中都排除1.4.6,因为我将显式包含另一个工件rtds-framework-client (不同的工件名称),该子项与子POM中的<dependency>向下兼容1.4.6。

如果必须使用<exclusion> ,则必须在所有依赖项中明确给出。 因此,我决定采用<scope>provided</scope>方式。

我的问题基于的已知的Maven信息:

如果我将以下内容包含在子POM中(版本高于1.4.6,则所有传递依赖项中的rtds-client都将移至1.8。我可以从Eclipse的'Dependency Hierarchy'中看到'omitted for conflict with 1.8' [compile],这意味着它将考虑/覆盖子POM中指定的版本idi-persistence现在为1.8)。

<dependency>
    <groupId>com.company.rtdp.rtds</groupId>
    <artifactId>rtds-client</artifactId>
    <version>1.8</version>
</dependency>

题:

如果我将以下内容包含在子POM中,而没有<dependencyManagement>

<dependency>
    <groupId>com.company.rtdp.rtds</groupId>
    <artifactId>rtds-client</artifactId>
    <version>1.4.6</version>
    <scope>provided<scope>
</dependency>

所述的无rtds-client这是作为传递依赖认为provided而我提到的相同的范围内<dependencyManagement>无论是在父节点或子POM,标签provided范围被施加。

为什么version得到的影响,但没有scope给出里面<dependency>标记和scope (对于这种使用情况下),我必须去<dependencyManagement>

说如果允许的话,它将导致我们陷入什么问题?

编辑:

i)在子POM或父POM中<scope>provided<dependencyManagement>/<dependencies>/<dependency> <scope>provided

在此处输入图片说明

尽管省略了较长的路径,但在此处说[provided]

[INFO] +- com.company.idi:idi-persistence:jar:3.3:compile
[INFO] |  +- com.company.rtdp.rtds:realtimedataserv-client:jar:1.4.6:provided

ii)在子POM中直接具有<dependencies>/<dependency> <scope>provided <dependencyManagement>周围没有<dependencyManagement>

在此处输入图片说明

尽管省略了较长的路径,但它并没有说明provided路径,而只是单独compile

[INFO] --- maven-dependency-plugin:2.3:tree (default-cli) @ read-rest-service ---
[INFO] +- com.company.rtdp.rtds:realtimedataserv-client:jar:1.4.6:provided (scope not updated to compile)

===============>>#1 票数:2

我无法理解您在<dependencyManagement><dependency <scope>provided<scope>provided

如果我声明一个子POM,则在父中没有任何dependency[Management] ,例如:

<project ...>
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>igb.so</groupId>
        <artifactId>SO-44987444-parent</artifactId>
        <relativePath>../SO-44987444-parent</relativePath>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>SO-44987444-child</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-text</artifactId>
            <version>1.1</version>
            <!--  has a dependency of org.apache.commons:commons-lang3:jar:3.5:compile -->
        </dependency>
    </dependencies>

</project>

dependency:tree看起来像:

[INFO] ------------------------------------------------------------------------
[INFO] Building SO-44987444-child 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ SO-44987444-child ---
[INFO] igb.so:SO-44987444-child:jar:0.0.1-SNAPSHOT
[INFO] \- org.apache.commons:commons-text:jar:1.1:compile
[INFO]    \- org.apache.commons:commons-lang3:jar:3.5:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

如果我将commons-lang3添加为<scope>provided直接依赖项:

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.5</version>
            <scope>provided</scope>
        </dependency>

dependency:tree看起来像:

[INFO] ------------------------------------------------------------------------
[INFO] Building SO-44987444-child 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ SO-44987444-child ---
[INFO] igb.so:SO-44987444-child:jar:0.0.1-SNAPSHOT
[INFO] +- org.apache.commons:commons-text:jar:1.1:compile
[INFO] \- org.apache.commons:commons-lang3:jar:3.5:provided
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

即使我添加到父POM:

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.5</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

dependency:tree结果没有什么不同。

  ask by user104309 translate from so

未解决问题?本站智能推荐: