有没有办法让只有一个特定的依赖的运行时依赖?

问题描述 投票:1回答:1

我有一个多模块Maven项目。有些模块是别人的依赖,而一个单独的项目[公地回购]有一个在我的主要项目依赖的模块。

我能够创建一个中介模块,将收集运行时罐子,我能够传递下去,但是当我尝试纳入德相同的代码到不同的模块,它拉的所有运行时罐子,而不仅仅是特定的依赖。下面的代码。

群ID B是外部的“公地”的项目,我们在多个项目中使用。

<dependency>
     <groupId>B</groupId>
     <artifactId>B.artifact2</artifactId>
     <version>${B.version}</version>
</dependency>   

我能够创建一个单独的[中介]模块只B.artifact2作为唯一的依赖,并用下面的代码运行时罐子拉进自己的$ {} project.build.directory /目标文件夹

<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<executions>
  <execution>
    <id>1</id>
    <phase>prepare-package</phase>
    <goals>
      <goal>copy-dependencies</goal>
    </goals>
    <configuration>
      <includeScope>runtime</includeScope>
      <excludeGroupIds>com.google.code.findbugs,net.jcip</excludeGroupIds>
      <outputDirectory>${project.build.directory}/dependency-jars</outputDirectory>
    </configuration>
  </execution>

完美的作品[让我的〜15个罐子我需要],但我们不希望使用中介模块。我试图将其写入主模块[,中介将是一个依赖关系],但我没有选择只有特定依赖,以获得运行时JAR的方式,而不是它拉几乎所有运行时依赖到该文件夹​​。该项目是这样的:

    <dependency>
        <groupId>A</groupId>
        <artifactId>A.artifact</artifactId>
        <version>${A.version}</version>
        <classifier>dist</classifier>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>B</groupId>
        <artifactId>B.artifact1</artifactId>
        <version>${B.version}</version>
    </dependency>
    <dependency>
        <groupId>B</groupId>
        <artifactId>B.artifact2</artifactId>
        <version>${B.version}</version>
    </dependency>

我在这个模块,并使用如下的东西多的依赖仍将拉在所有运行时依赖[〜40瓶]

      <execution>
          <id>test</id>
          <phase>package</phase>
          <goals>
              <goal>copy-dependencies</goal>
          </goals>
          <configuration>
              <includeScope>runtime</includeScope>
              <excludeGroupIds>A,C,D,com.google.code.findbugs,net.jcip</excludeGroupIds>
              <outputDirectory>${project.build.directory}/dependency-jars</outputDirectory>
          </configuration>
      </execution>

如果我尝试将其限制在B.artifact2,我只得到从B.artifact2神器和它不运行时JAR /依赖...

我是被迫使用中介模块,然后使用它作为主模块的依赖?

maven
1个回答
0
投票

在我看来,你在错误的方向首先使用copy-dependencies开始。

在Maven的时候,你不绕复制它们处理的依赖关系,而是你在POM的依赖部分定义它们,并从Maven仓库拉他们。

在公司,你通常运行在服务器上的Nexus / Artifactory的,并使用它。

你也可以使用Maven本地仓库,如果你的项目规模小,你只是一个开发商。在任何情况下,不要试图从一个项目复制依赖到另一个。

© www.soinside.com 2019 - 2024. All rights reserved.