我目前正在尝试将 BOM( Material list )文件引入我的 Maven 项目,但它似乎不起作用,我也不知道为什么。
这是我的出生:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.private</groupId>
<artifactId>test.bom</artifactId>
<version>5.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<version.CoreAnnotation>5.0.0-SNAPSHOT</version.CoreAnnotation>
<version.CoreWeb>5.0.0-SNAPSHOT</version.CoreWeb>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.private</groupId>
<artifactId>CoreAnnotation</artifactId>
<version> ${version.CoreAnnotation}</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.private</groupId>
<artifactId>CoreWeb</artifactId>
<version>${version.CoreWeb}</version>
<type>war</type>
</dependency>
</dependencies>
</dependencyManagement>
</project>
还有更多,但我排除了它们,因为我认为这应该足以作为示例。
这是我的pom(我尝试在其中包含 bom):
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>Core</artifactId>
<groupId>com.private</groupId>
<version>5.0.0-SNAPSHOT</version>
</parent>
<artifactId>Core-ear</artifactId>
<packaging>ear</packaging>
<name>Core-ear: EAR Module for private</name>
<properties>
<version.test.bom>5.0.0-SNAPSHOT</version.test.bom>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.private</groupId>
<artifactId>test.bom</artifactId>
<version>${version.test.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
每当我使用 maven install 时,依赖项部分中定义的所有包的集合都应该出现在文件夹\target\Core-ear\
现在的问题是:bom 中定义的依赖项没有出现在那里。可能是什么问题?
ps:运行 mvn install -X
进行调试似乎没有帮助。
最佳答案
发生这种情况是因为您没有在 POM 中声明依赖项。您只声明了 <dependencyManagement>
部分。
在 POM 中,您需要添加以下依赖项(不包含版本):
<dependencies>
<dependency>
<groupId>com.private</groupId>
<artifactId>CoreAnnotation</artifactId>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.private</groupId>
<artifactId>CoreWeb</artifactId>
<type>war</type>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.private</groupId>
<artifactId>test.bom</artifactId>
<version>${version.test.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
引用Introduction to the Dependency Mechanism :BOM 用于考虑所有 Artifact 的版本,因此您不需要将其添加到 <dependency>
中部分。
关于java - 为什么我的 Maven 不使用定义的 BOM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33936395/