【问题标题】:My tests were running and then I clicked "Run as --> Maven clean" and now when I click "Run as --> Maven test" it doesn't work anymore我的测试正在运行,然后我单击“运行为--> Maven clean”,现在当我单击“运行为--> Maven 测试”时,它不再工作了
【发布时间】:2020-06-02 00:35:12
【问题描述】:

我的项目在 Eclipse 中右键单击 pom.xml 文件并选择:“Run as --> Maven install”,然后“Run as --> Maven test”。

我开始尝试并选择:“运行方式--> Maven clean”,然后选择“运行方式--> Maven 安装”。这一次,我遇到了构建错误,无法运行“Run as --> Maven test”。发生了什么?为什么会出现构建错误?

如果我退出 Eclipse,删除 .m2 文件夹中的所有内容,重新启动 Eclipse,然后单击“Run as --> Maven install”两次(第一次产生错误,第二次成功)。我不知道为什么会这样。我对“Maven clean”、“Maven install”和“Maven test”的作用感到困惑。是的,我已经阅读了documentation on 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] ------------------------------------------------------------------------

【问题讨论】:

  • 你有哪个JDK版本?
  • 错误只是说JDK编译器版本设置为5,必须大于jdk 6
  • @UnknownBeast 我正在使用 Maven 项目的默认值:J2SE 1.5。如何更改?
  • 右键单击 JRE 系统库 -> 构建路径 -> 配置构建路径 -> 在库选项卡中单击 JRE 系统库 -> 单击编辑按钮(右侧) -> 选中备用 JRE然后单击 Installed JRE 按钮 -> 单击添加按钮,然后单击目录按钮,然后选择包含 bin 和其他文件夹的 JDK 主目录
  • 在此之前确保您的系统中安装了 JDK 而不是 JRE

标签: java eclipse maven cucumber qa


【解决方案1】:

maven 编译器插件默认为 Java 1.5,但您使用的 JDK 版本不再支持。您可以通过将编译器插件配置为使用不同版本的 java 来解决此问题。

https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-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>

【讨论】:

    猜你喜欢
    • 2021-10-19
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多