【发布时间】:2019-06-22 04:20:05
【问题描述】:
我的项目由 Maven 驱动,使用不是我自己制作的 POM (from Vaadin)。显然,我在项目中看到的 POM 文件依赖于其他 POM 文件的某种继承。虽然我在自己的 POM 中没有看到 maven-surefire-plugin 的依赖项,但在我的项目中找到了这个工件,正如您在 IntelliJ 2019 的此屏幕截图的右侧看到的那样。
我不是 Maven 专家,所以我不知道确切的细节,但在四处寻找时我发现了一些 import 行,所以我猜测 Maven POM 可以动态地从其他 POM 继承。
问题是我的项目中存在的maven-surefire-plugin 版本相当旧,版本为2.12.4。我正在尝试运行JUnit 5,requires 2.22.0 或更高版本。 current version 是 3.0.0-M3。
查看那个粉红色箭头的左端,您可以看到我在 POM 中添加了一个 dependency 元素。
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</dependency>
在左箭头提示中,我要求3.0.0-M3 尝试覆盖右箭头提示中神秘导入/继承的指定版本2.12.4。但是我的尝试失败了,因为在执行 Maven clean、install 之后旧版本仍然存在。我什至尝试重新启动 IntelliJ。但是不行,在运行 Maven test 时,我的 JUnit 5 测试仍然被忽略。
➥ 有没有办法覆盖显然是从某个神秘来源继承的依赖版本?
这是我的 POM,在尝试添加 <artifactId>maven-surefire-plugin</artifactId> 依赖项失败之前。
<?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.basilbourque.acmeapp</groupId>
<artifactId>acmeapp</artifactId>
<name>AcmeApp</name>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
<!--<vaadin.version>11.0.1</vaadin.version>-->
<!--<vaadin.version>12.0.0.beta1</vaadin.version>-->
<vaadin.version>13.0.0.alpha3</vaadin.version>
</properties>
<repositories>
<!-- Repository used by many Vaadin add-ons -->
<repository>
<id>Vaadin Directory</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
<repository>
<id>vaadin-prereleases</id>
<url>https://maven.vaadin.com/vaadin-prereleases</url>
</repository>
</repositories>
<pluginRepositories>
<!-- Repository needed for prerelease versions of Vaadin -->
<pluginRepository>
<id>vaadin-prereleases</id>
<url>https://maven.vaadin.com/vaadin-prereleases</url>
</pluginRepository>
</pluginRepositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<type>pom</type>
<scope>import</scope>
<version>${vaadin.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-core</artifactId>
</dependency>
<!-- Added to provide logging output as Flow uses -->
<!-- the unbound SLF4J no-operation (NOP) logger implementation -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<!--<version>3.1.0</version>-->
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<!--JUnit 5-->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.4.0-RC1</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Jetty plugin for easy testing without a server -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.14.v20181114</version>
<configuration>
<scanIntervalSeconds>1</scanIntervalSeconds>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- Production mode can be activated with either property or profile -->
<id>production-mode</id>
<activation>
<property>
<name>vaadin.productionMode</name>
</property>
</activation>
<properties>
<vaadin.productionMode>true</vaadin.productionMode>
</properties>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-server-production-mode</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.version}</version>
<executions>
<execution>
<goals>
<goal>copy-production-files</goal>
<goal>package-for-production</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
【问题讨论】:
-
通过在 pluginManagement 中定义插件版本而被覆盖,并且永远不会作为依赖项......此外,如果您使用 JDK9+,您应该使用
<maven.compiler.release>11</maven.compiler.release>而不是目标/源。此外,如果您喜欢使用 Junit Jupiter,此设置也不正确... -
@khmarbaise Jupiter 设置有什么问题?
标签: maven intellij-idea pom.xml maven-surefire-plugin