我的项目由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。但是,我的JUnit 5测试在运行Maven test
时仍然被忽略。
➥有什么方法可以替代显然是从某些神秘来源继承来的依赖版本?
这是我的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>
答案 0 :(得分:1)
<plugin>
,而不是<dependency>
虽然我不是Maven专家,但解决方案似乎是在<artifactId>maven-surefire-plugin</artifactId>
元素而不是plugin
元素中指定dependency
。
删除添加的<dependency>
。
查找POM的<plugins>
(复数)部分,其中包含一个<plugin
元素用于Jetty。添加第二个plugin
元素:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
然后执行Maven clean
和install
。您应该看到新版本出现在IntelliJ的 Maven 面板中。
您现在可以执行Maven test
来查看已执行的JUnit 5测试。
如果需要,可以通过覆盖导入的POM来更新屏幕快照右侧列出的所有那些插件。
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-clean-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-deploy-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<!--https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-install-plugin-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-resources-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!--https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-war-plugin-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-site-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<!--https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>