You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Java+Maven+Cucumber+JUnit框架配置Allure报告时Maven执行测试出现VM崩溃及插件加载失败问题求助

Fix: Forked VM Terminated Error with Allure Cucumber4 & Maven

Let's break down your problem and fix it step by step:

Core Issue

The error happens because the Maven Surefire plugin is misinterpreting your cucumber.options parameter — it's treating the entire "-Dcucumber.options=..." string as a main class to load, which obviously doesn't exist. This causes the forked VM to crash abruptly.

Step-by-Step Solutions

1. Correct Maven Surefire Plugin Configuration

The way you pass cucumber.options to Surefire is critical. Here are two valid, reliable approaches:

Option A: Use <systemPropertyVariables> (Recommended)

This avoids any quoting or parsing issues entirely:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M7</version> <!-- Use a stable, compatible version -->
            <configuration>
                <systemPropertyVariables>
                    <cucumber.options>--plugin io.qameta.allure.cucumber4jvm.AllureCucumber4Jvm --features src/test/resources/features</cucumber.options>
                    <!-- Add glue paths or other cucumber flags here if needed -->
                </systemPropertyVariables>
            </configuration>
        </plugin>
    </plugins>
</build>

Option B: Fix <argLine> Format

If you prefer using <argLine>, make sure you don't wrap the entire -D parameter in extra quotes:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M7</version>
    <configuration>
        <argLine>-Dcucumber.options=--plugin io.qameta.allure.cucumber4jvm.AllureCucumber4Jvm --features src/test/resources/features</argLine>
        <!-- Add memory flags if you hit OOM issues: -Xmx1024m -Xms512m -->
    </configuration>
</plugin>

2. Verify Allure Cucumber4 Dependencies

Double-check your pom.xml has the correct Allure dependencies for Cucumber4 (match versions to avoid compatibility gaps):

<dependencies>
    <!-- Allure Cucumber4 Integration -->
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-cucumber4-jvm</artifactId>
        <version>2.17.3</version> <!-- Match your Allure report version -->
        <scope>test</scope>
    </dependency>
    <!-- Allure JUnit4 Integration (required for test lifecycle hooks) -->
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-junit4</artifactId>
        <version>2.17.3</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Also ensure the Allure Maven plugin is set up to generate reports post-test:

<build>
    <plugins>
        <plugin>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-maven</artifactId>
            <version>2.11.2</version>
            <configuration>
                <reportVersion>2.17.3</reportVersion>
            </configuration>
        </plugin>
    </plugins>
</build>

3. Troubleshoot Persistent VM Crash Issues

If you still see the "forked VM terminated" error after fixing the parameter:

  • Check for System.exit() calls: Make sure none of your test code, hooks, or helper classes are calling System.exit() — this will immediately kill the forked VM.
  • Increase VM memory: Add memory flags to <argLine> like -Xmx1024m -Xms512m to prevent out-of-memory crashes.
  • Update dependencies: Try upgrading to the latest stable Surefire plugin version (3.x series) and ensure your Maven version is compatible with it.

4. Validate the Fix

  1. Run mvn clean test to execute tests via Maven
  2. If tests pass, run mvn allure:serve to generate and open the Allure report in your browser

内容的提问来源于stack exchange,提问作者Anas Khan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 05:57:33