Maven继承了从项目到另一个项目的依赖关系

时间:2013-08-01 19:50:14

标签: java maven bamboo

鉴于Maven项目A生产一个罐子:

<groupId>myprojects</groupId>
<artifactId>A</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
    <dependency>
        <groupId>some.needed.group</groupId>
        <artifactId>some.needed.artifact1</artifactId>
    </dependency>
    <dependency>
        <groupId>some.needed.group</groupId>
        <artifactId>some.needed.artifact2</artifactId>
    </dependency>
</dependencies>

和项目B依赖于A并生成企业档案:

<groupId>myprojects</groupId>
<artifactId>B</artifactId>
<version>1.0</version>
<packaging>ear</packaging>
<dependencies>
    <dependency>
        <artifactId>A</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies>

如何让项目B ear工件不仅包含项目B的jar工件,还包括其依赖工件some.needed.artifact1和some.needed.artifact2?


我编辑并添加了这个,因为似乎只有在从Bamboo运行mvn时才会发生这种行为: 奇怪的是,当我从Eclipse本地运行mvn时它正在工作,但是当它由Bamboo持续集成服务器运行时却没有。在本地运行中,我正确生成了application.xml,并引用了相应jar文件复制到lib文件夹的所有传递依赖项。在Bamboo计划中,生成的application.xml不包含引用,并且jar文件不在lib文件夹中。

2 个答案:

答案 0 :(得分:0)

首先作为修正,我认为依赖应该是A,而不是B,就像这样:

   <dependencies>
    <dependency>
        <artifactId>A</artifactId>
        <version>1.0</version>
    </dependency>
 </dependencies>

关于拥有依赖jar的原始问题,我认为它们应该在您的EAR文件中可用,因为您依赖于A project,而这依赖于some.needed.artifact1 and some.needed.artifact2(传递依赖)因为你提供的范围是默认,所以maven将把它作为编译,所有的jar都会捆绑在你的ear文件中。

由于

答案 1 :(得分:-1)

在生成耳朵的项目B中,您可以像这样包含对A的依赖

<modules>
  <module>project A</module>
</modules>
<dependencies>
  <dependency>
    <groupId>some.needed.group</groupId>
    <artifactId>A</artifactId>
    <version>1.0</version>
  </dependency>
</dependencies>

在项目A中,将父项目定义为项目B,如下所示

<parent>
        <groupId>myprojects</groupId>
        <artifactId>B</artifactId>
        <version>1.0</version>
        <name>project B</name>
</parent>
<name>project A</name>
相关问题