在Eclipse中右击pom.xml文件并选择:"Run as --> Maven install",然后选择 "Run as --> Maven test",我的项目就成功了。"Run as --> Maven install",然后 "Run as --> Maven test"。
我开始实验了一下,选择了:"Run as --> Maven install",然后选择:"Run as --> Maven test"。"Run as --> Maven clean",然后选择 "Run as --> Maven install"。这次我遇到了构建错误,无法运行 "Run as --> Maven test"。到底发生了什么?为什么我得到了构建错误?
如果我退出Eclipse,删除.m2文件夹中的所有内容,重新启动Eclipse,然后点击两次 "Run as --> Maven install"(第一次产生错误,第二次成功),就能让测试重新运行。我不知道为什么会这样。我对 "Maven clean"、"Maven install "和 "Maven test "的作用感到困惑。是的,我已经阅读了 "Maven清洁"、"Maven安装 "和 "Maven测试"。maven.apache.org上的文档 但我还是很困惑。
这是我的pom.xml。
<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.ah</groupId>
<artifactId>goToLinks</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>GoToLinks</name>
<dependencies>
<!-- selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>5.7.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<parallel>methods</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>
</plugin>
</plugins>
</build>
</project>
这是我得到的错误信息:
[INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] Source option 5 is no longer supported. Use 7 or later. [ERROR] Target option 5 is no longer supported. Use 7 or later. [INFO] 2 errors [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.540 s [INFO] Finished at: 2020-06-01T19:47:03-04:00 [INFO] ------------------------------------------------------------------------
maven编译器插件默认为Java 1.5,但你使用的JDK版本已经不支持了。你可以通过配置编译器插件使用不同版本的java来解决这个问题。
https:/maven.apache.orgpluginsmaven-compiler-pluginexamplesset-compiler-source-and-target.html)。
<project>
[...]
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
[...]
</project>
或直接配置插件。
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>