0

I have an intricated Maven project with modules and subprojects up to four level of inheritance. Furthermore, some modules depend on modules which are not in the same "subtree" and I am wondering if I can avoid to express the version every time I have module dependency.

For example I have

a
 -b
   -c
 -d
   -e

Supposing module e depends on c, what is the best way to specify the version in a DRY manner?

If inside the pom.xml of module e I don't specify which version of the c module I want, my build will fail. Is there a smart way to handle this versioning problem?

4

2 回答 2

2

groupId 和 artifactId 表示 maven 中的单个项目,但必须指定版本(或从父 pom 继承)以确定该项目 maven 需要引用的版本。它看起来是多余的,但它是必要的,特别是如果有许多不同的版本。

于 2013-01-18T13:34:40.097 回答
1

最好的方法是在项目根目录的 dependencyManagement 块中定义所有工件及其适当的版本号,例如:

a (pom.xml)
 -b
   -c
 -d
   -e

具有以下内容:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>project</groupId>
      <artifactId>b</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
      <groupId>project</groupId>
      <artifactId>c</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
      <groupId>project</groupId>
      <artifactId>d</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
      <groupId>project</groupId>
      <artifactId>e</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>
</dependencyManagement>

但是对于给定的结构:

a (pom.xml)
 -b
   -c
 -d
   -e

a 必须包含模块列表(打包 pom)、b(打包 pom)和 d(打包 pom),这意味着 a、b 和 d 永远不会用作依赖项,这意味着您可以从上面的块中省略它们。

于 2013-01-20T16:26:12.710 回答