运行Feature文件时遇Main类弃用警告,多次尝试仍未解决
解决Cucumber运行Feature文件时的过时类警告
运行Feature文件时出现如下警告:
Sep 25, 2023 1:34:54 AM cucumber.api.cli.Main run WARNING: You are using deprecated Main class. Please use io.cucumber.core.cli.Main
你提到多次重建项目、调整依赖都没解决,其实这个问题和依赖本身关系不大,核心是你运行Cucumber时调用的还是旧的过时主类,而非新版本要求的类。以下是具体解决方法:
- 修改IDE运行配置:如果是直接在IDE(比如IntelliJ/Eclipse)里运行Feature文件,找到对应的运行配置,将主类从
cucumber.api.cli.Main替换为io.cucumber.core.cli.Main。 - 检查Maven插件配置(如果用Maven命令运行):确保你的
cucumber-maven-plugin插件配置里指定了正确的主类,并且插件版本和你的Cucumber依赖版本(7.14.0)保持一致,示例配置如下:
<plugin> <groupId>io.cucumber</groupId> <artifactId>cucumber-maven-plugin</artifactId> <version>7.14.0</version> <configuration> <mainClass>io.cucumber.core.cli.Main</mainClass> <!-- 其他配置比如features路径、glue包等 --> </configuration> </plugin>
- 清理冗余依赖:你当前依赖里的
gherkin不需要手动添加,cucumber-java已经内置了适配版本的gherkin,手动引入可能引发版本冲突,建议删除该依赖项。调整后的依赖配置如下:
<dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>7.14.0</version> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-testng</artifactId> <version>7.14.0</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.13.0</version> </dependency>
内容的提问来源于stack exchange,提问作者Vaibhav Yadav
相关产品推荐
相关产品推荐

