Java+Maven+Cucumber+JUnit框架配置Allure报告时Maven执行测试出现VM崩溃及插件加载失败问题求助
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 callingSystem.exit()— this will immediately kill the forked VM. - Increase VM memory: Add memory flags to
<argLine>like-Xmx1024m -Xms512mto 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
- Run
mvn clean testto execute tests via Maven - If tests pass, run
mvn allure:serveto generate and open the Allure report in your browser
内容的提问来源于stack exchange,提问作者Anas Khan

