在子 pom 中引用父 pom 的依赖项版本
Referencing version of a dependency from parent pom in child pom
我有一个父 pom,它像这样在 dependencyManagement 块中定义依赖项
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.tibco.plugins</groupId>
<artifactId>com.tibco.bw.palette.shared</artifactId>
<version>6.1.100</version>
</dependency>
</dependencies>
</dependencyManagement>
在子 pom 中,我正在使用这样的依赖项
<dependencies>
<dependency>
<groupId>com.tibco.plugins</groupId>
<artifactId>com.tibco.bw.palette.shared</artifactId>
<scope>provided</scope>
</dependency>
问题是当我打开项目是一个自定义的Eclipse IDE,我有这个错误,它无法理解版本在父pom
我需要一些方法来在子 pom 中引用父 pom 的版本而不重新定义它
谢谢
在属性 X.X 下的父 pom 中添加依赖项版本,并在子项中使用占位符引用它。实际上,您也可以省略父项之外的相同项目属性,因为它们将从父项继承。 – 来自 WhoCares
试试这个...
在你的 parent pom
<groupId>my.project</groupId>
<artifactId>myproject-parent</artifactId>
<version>MYPROJECT-1.0</version>
<packaging>pom</packaging>
<properties>
<com.tibco.bw.palette.shared.version>6.1.100</com.tibco.bw.palette.shared.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.tibco.plugins</groupId>
<artifactId>com.tibco.bw.palette.shared</artifactId>
<version>${com.tibco.bw.palette.shared.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
然后在你的 child pom
<parent>
<groupId>my.project</groupId>
<artifactId>myproject-parent</artifactId>
<version>MYPROJECT-1.0</version>
<relativePath>..</relativePath>
</parent>
<groupId>my.project.child</groupId>
<artifactId>myproject-child</artifactId>
<version>MYPROJECT-1.0</version>
<dependencies>
<dependency>
<groupId>com.tibco.plugins</groupId>
<artifactId>com.tibco.bw.palette.shared</artifactId>
</dependency>
</dependencies>
正确建立 parent / child 关系 set-up 很重要。另请注意,dependencyManagement
仅在 Maven 层次结构中工作一个级别(即它不会在 "grand children" 上工作)
我有一个父 pom,它像这样在 dependencyManagement 块中定义依赖项
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.tibco.plugins</groupId>
<artifactId>com.tibco.bw.palette.shared</artifactId>
<version>6.1.100</version>
</dependency>
</dependencies>
</dependencyManagement>
在子 pom 中,我正在使用这样的依赖项
<dependencies>
<dependency>
<groupId>com.tibco.plugins</groupId>
<artifactId>com.tibco.bw.palette.shared</artifactId>
<scope>provided</scope>
</dependency>
问题是当我打开项目是一个自定义的Eclipse IDE,我有这个错误,它无法理解版本在父pom
我需要一些方法来在子 pom 中引用父 pom 的版本而不重新定义它
谢谢
在属性 X.X 下的父 pom 中添加依赖项版本,并在子项中使用占位符引用它。实际上,您也可以省略父项之外的相同项目属性,因为它们将从父项继承。 – 来自 WhoCares
试试这个...
在你的 parent pom
<groupId>my.project</groupId>
<artifactId>myproject-parent</artifactId>
<version>MYPROJECT-1.0</version>
<packaging>pom</packaging>
<properties>
<com.tibco.bw.palette.shared.version>6.1.100</com.tibco.bw.palette.shared.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.tibco.plugins</groupId>
<artifactId>com.tibco.bw.palette.shared</artifactId>
<version>${com.tibco.bw.palette.shared.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
然后在你的 child pom
<parent>
<groupId>my.project</groupId>
<artifactId>myproject-parent</artifactId>
<version>MYPROJECT-1.0</version>
<relativePath>..</relativePath>
</parent>
<groupId>my.project.child</groupId>
<artifactId>myproject-child</artifactId>
<version>MYPROJECT-1.0</version>
<dependencies>
<dependency>
<groupId>com.tibco.plugins</groupId>
<artifactId>com.tibco.bw.palette.shared</artifactId>
</dependency>
</dependencies>
正确建立 parent / child 关系 set-up 很重要。另请注意,dependencyManagement
仅在 Maven 层次结构中工作一个级别(即它不会在 "grand children" 上工作)