【发布时间】:2018-05-08 20:16:24
【问题描述】:
根据最新发布的JUnit v. 5.2,现在有一个BOM:
JUnit BOM:为了简化使用 Maven 或 Gradle 的依赖关系管理,现在在 org.junit:junit-bom:5.2.0 Maven 坐标下提供了物料清单 POM。
作为一个起点,目前我的 POM 如下所示:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bosspanda.tmp</groupId>
<version>0.1-SNAPSHOT</version>
<artifactId>tmp</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
<java.version>10</java.version>
<junit.version>4.12</junit.version>
<junit.jupiter.version>5.2.0</junit.jupiter.version>
<junit.vintage.version>5.2.0</junit.vintage.version>
<junit.platform.version>1.2.0</junit.platform.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
如果我正确理解了上面的这个 BOM 发行说明,它就是将这个 junit <dependency> 标记简化为单个 BOM 依赖项。
但是,我在将它集成到我的项目的 pom.xml 中时遇到了严重的麻烦。在查看了链接资源 (https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies) 之后,我得出结论,我必须用一个单独的依赖项替换不同的依赖项:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.2.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
但是有了这个 IntelliJ IDEA (v. 2018.1.3 Ultimate x64, Maven v. 3.5.3, target JDK 10.0.1) 似乎不知道<dependencyManagement> 标签是什么并且不解析其内容.项目结构中未注册任何模块。
但如果我删除 <dependencyManagement> 标签,IDEA 也不会加载 BOM。
我还尝试使用 maven 插件通过 IDEA 添加 BOM 的 maven 坐标,但是当它找到不同的 junit 包时,它没有找到 BOM 并且无法从 org.junit:junit-bom:5.2.0 下载任何东西
如何将此 BOM 文件添加到我的 pom 依赖项中?
谢谢!
【问题讨论】:
-
Jens Piegsa 的回答是正确的,你可以在这里找到一个例子:github.com/junit-team/junit5-samples/commit/…
-
@SamBranen 感谢您提供的链接,这很有帮助!
标签: maven junit pom.xml junit5 maven-bom