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

Cucumber新人求助:旧Main类弃用+TagExpressionParser缺失引发报错

Fixing Your Cucumber Deprecation Warning & NoClassDefFoundError

Hey there! Let's tackle your Cucumber issues one by one—they're super common when working with newer versions, so don't stress.

First: Fix the Deprecation Warning

The warning is straightforward: the old cucumber.api.cli.Main class has been retired in newer Cucumber releases. You just need to replace it with the updated main class:
io.cucumber.core.cli.Main

This is a breaking change introduced in Cucumber 4.x+, so updating your run configuration or main class reference to use the new path will get rid of that warning right away.

Second: Resolve the NoClassDefFoundError for TagExpressionParser

This error means your project can't locate the io.cucumber.tagexpressions.TagExpressionParser class, which almost always stems from missing or mismatched dependencies. Here's how to fix it:

1. Unify All Cucumber Dependency Versions

Cucumber's components (core, java, tag-expressions, etc.) need to be on the same version to avoid compatibility clashes.

If you're using Maven, update your pom.xml with consistent versions like this:

<dependencies>
    <!-- Cucumber core dependencies -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>7.14.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>7.14.0</version>
        <scope>test</scope>
    </dependency>
    <!-- Tag expressions (sometimes needs explicit inclusion) -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-tag-expressions</artifactId>
        <version>7.14.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

If you're using Gradle, adjust your build.gradle similarly:

dependencies {
    testImplementation 'io.cucumber:cucumber-java:7.14.0'
    testImplementation 'io.cucumber:cucumber-core:7.14.0'
    testImplementation 'io.cucumber:cucumber-tag-expressions:7.14.0'
}

(Note: Pick a stable recent version—7.x is the current major release as of now.)

2. Check for Dependency Conflicts

Sometimes older, conflicting Cucumber dependencies sneak into your project via other libraries. For example, if another dependency pulls in an old cucumber-jvm version, it can clash with your new setup.

  • In Maven, run mvn dependency:tree to spot conflicting versions, then exclude the old ones from the problematic dependency.
  • In Gradle, use ./gradlew dependencies to inspect the dependency tree and resolve conflicts.

3. Refresh & Rebuild Your Project

After updating dependencies:

  • Clean your project (Maven: mvn clean, Gradle: ./gradlew clean)
  • Rebuild to fetch the correct dependencies
  • Restart your IDE to ensure the classpath is updated

4. If Running JARs Directly

If you're executing Cucumber via standalone JARs, make sure all required JARs are included in your classpath. You can't run just cucumber-java.jar—you need cucumber-core.jar, cucumber-tag-expressions.jar, and any other related dependencies in the classpath when launching the main class.

Final Quick Check

Once you've made these changes, run your Cucumber tests again. The deprecation warning should be gone, and the NoClassDefFoundError should resolve because the missing class will now be present in your project's classpath.

内容的提问来源于stack exchange,提问作者aarya diwakar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 20:17:33