我有一个多模块Maven项目。有些模块是其他模块的依赖项,而一个单独的项目(一个公共仓库)包含的模块是我主项目中的依赖项。
我能够创建一个中介模块,将收集运行时罐子,我能够传递下去,但是当我尝试纳入德相同的代码到不同的模块,它拉的所有运行时罐,而不是仅仅是具体的依赖性。下面的代码。
GroupID B是我们在多个项目中使用的外部“常见”项目。
<dependency>
<groupId>B</groupId>
<artifactId>B.artifact2</artifactId>
<version>${B.version}</version>
</dependency>
我能够使用B.artifact2作为唯一的依赖关系来创建单独的[intermediary]模块,并使用以下代码将运行时jar放入其自己的$ {project.build.directory} / target文件夹中
<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 /依赖项...
我是否被迫使用中介模块,然后将其用作主模块的依赖项?
答案 0 :(得分:0)
在我看来,您首先使用copy-dependencies
进入了错误的方向。
在Maven中,您不通过复制依赖关系来处理依赖关系,而是在POM的依赖关系部分中定义它们并将它们从Maven存储库中提取。
在公司中,通常会在服务器上运行Nexus / Artifactory并使用它。
如果您的项目很小并且您只是一名开发人员,则也可以使用Maven本地存储库。无论如何,请勿尝试将依赖项从一个项目复制到另一个项目。