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

在Eclipse运行Cucumber脚本时遇NoSuchMethodError错误求助

Fixing Cucumber Initialization Error: java.lang.NoSuchMethodError: cucumber.runtime.RuntimeOptions.<init>(Ljava/util/Properties;[Ljava/lang/String;)V

Hey, I’ve run into this exact Cucumber initialization error in Eclipse countless times—almost always it boils down to mismatched dependency versions causing method signature conflicts. Let’s walk through the fixes step by step:

  • Ensure all Cucumber dependencies use the same version
    This is the #1 culprit. Components like cucumber-java, cucumber-junit, cucumber-core, and cucumber-html must share the exact same version number. Mixing major/minor versions (e.g., using Cucumber 5.x for some and 6.x for others) breaks internal method contracts like the RuntimeOptions constructor mentioned in your error.

    For Maven projects, update your pom.xml to lock in a consistent version (example using Cucumber 6.11.0):

    <dependencies>
        <!-- Cucumber core dependencies -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>6.11.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>6.11.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>6.11.0</version>
            <scope>test</scope>
        </dependency>
        <!-- JUnit dependency (match with Cucumber version) -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    

    For Gradle projects, do the same in build.gradle:

    testImplementation 'io.cucumber:cucumber-java:6.11.0'
    testImplementation 'io.cucumber:cucumber-junit:6.11.0'
    testImplementation 'junit:junit:4.13.2'
    
  • Verify JUnit and Cucumber compatibility
    Cucumber versions have strict JUnit requirements:

    • Cucumber 6.x+ requires JUnit 4.13.1 or higher.
    • If you’re using JUnit 5, you’ll need to replace cucumber-junit with cucumber-junit-platform-engine and add the JUnit 5 platform dependencies.
      Avoid mixing JUnit 4 and JUnit 5 dependencies in the same project—this often causes hidden conflicts.
  • Clean and refresh your Eclipse project
    Eclipse sometimes caches outdated dependency files, even after you update your build config. Fix this by:

    1. Right-click your project → Maven → Update Project (check "Force Update of Snapshots/Releases" if using Maven).
    2. Right-click your project → Clean → Clean Project.
    3. Restart Eclipse and re-run your TestRunner class.
  • Check your TestRunner class annotations
    Make sure you’re using the correct package for Cucumber annotations—old and new Cucumber versions use different package paths:

    • For Cucumber 4.x and earlier: cucumber.api.junit.Cucumber
    • For Cucumber 5.x and later: io.cucumber.junit.Cucumber

    Example of a correct TestRunner for modern Cucumber:

    import org.junit.runner.RunWith;
    import io.cucumber.junit.Cucumber;
    import io.cucumber.junit.CucumberOptions;
    
    @RunWith(Cucumber.class)
    @CucumberOptions(
        features = "src/test/resources/features",
        glue = "com.yourpackage.stepdefinitions"
    )
    public class TestRunner {
    }
    
  • Diagnose hidden dependency conflicts
    Use your build tool’s dependency tree command to find conflicting versions:

    • For Maven: Run mvn dependency:tree in your project root. Look for multiple versions of cucumber-core or other Cucumber components.
    • For Gradle: Run ./gradlew dependencies.

    If you find a conflicting dependency (e.g., a third-party library pulling in an older Cucumber version), exclude it from your build config. Example for Maven:

    <dependency>
        <groupId>com.some.library</groupId>
        <artifactId>problematic-library</artifactId>
        <version>1.0.0</version>
        <exclusions>
            <exclusion>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:47:21