引用共享依赖项版本 - 最佳实践是什么

时间:2012-02-02 12:36:11

标签: maven maven-3

我有一个共享依赖项,如下所示 -

    <groupId>common.spring</groupId>
    <artifactId>spring</artifactId>
    <version>3.0</version>
    <packaging>pom</packaging>
<modelVersion>4.0.0</modelVersion>

然后我使用:

引用此依赖项
<dependency>
            <groupId>common.spring</groupId>
            <artifactId>spring</artifactId>
            <version>3.0</version>
            <type>pom</type>
     </dependency>

我使用的是Spring 3.0版,通常的做法是将其设置为相同。所以只要标签匹配,这将有效。但是,如果我使用标签中使用的弹簧版本,常见的惯例是什么?

1 个答案:

答案 0 :(得分:0)

常见的约定是有一个根pom,定义版本,然后将版本信息保留在项目poms中,这样他们就可以从root pom中获取一个。

通常,Spring是一种特殊情况,因为它有多个模块,你想拥有相同的版本,所以像

  <properties>
    <spring.version>3.0.0</spring.version>
  </properties>

  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>${spring.version}</version>
  </dependency>
根pom中的

是我们使用的。在项目pom中,它将是这样的:

  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
  </dependency>

但是,如果将Spring视为常规模块,那么它只是

  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>3.0.0</version>
  </dependency>

在根pom中的依赖项部分和

  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
  </dependency>

项目pom。