serenity-bdd / serenity-cucumber4-starter

49 stars 73 forks source link

java.lang.NoClassDefFoundError: cucumber/runtime/io/ResourceLoader when trying to run tests through gradle. #33

Closed arpitsinghmrt closed 4 years ago

arpitsinghmrt commented 4 years ago

Hey @wakaleo , I followed the steps mentioned the readme as well as the documentation on serenity's site but I am still unable to run the tests I get the following error when I do gradle clean test

java.lang.NoClassDefFoundError: cucumber/runtime/io/ResourceLoader
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
    at java.lang.Class.getConstructor0(Class.java:3075)
    at java.lang.Class.getConstructor(Class.java:1825)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
    at org.junit.internal.requests.ClassRequest.createRunner(ClassRequest.java:28)
    at org.junit.internal.requests.MemoizingRequest.getRunner(MemoizingRequest.java:19)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:78)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
    at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: cucumber.runtime.io.ResourceLoader
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    ... 41 more

Below is my libraries.gradle

ext{
    slf4jVersion = '1.7.7'
    serenityCoreVersion = '2.2.2'
    serenityCucumberVersion = '2.1.2'
    junitVersion='4.13'
    assertJVersion='3.8.0'
    logbackVersion='1.2.3'
    cucumberVersion = '6.0.0-RC1'

    libs = [
            slf4jApi: "org.slf4j:slf4j-api:$slf4jVersion",
            logback: "ch.qos.logback:logback-classic:${logbackVersion}",

            test: [
                    serenity: [
                            core: "net.serenity-bdd:serenity-core:${serenityCoreVersion}",
                            junit: "net.serenity-bdd:serenity-junit:${serenityCoreVersion}",
                            screenplay: "net.serenity-bdd:serenity-screenplay:${serenityCoreVersion}",
                            screenplayWebdriver: "net.serenity-bdd:serenity-screenplay-webdriver:${serenityCoreVersion}",
                            cucumber: "net.serenity-bdd:serenity-cucumber4:${serenityCucumberVersion}",
                    ],
                    cucumber: [
                            java: "io.cucumber:cucumber-core:${cucumberVersion}",
                            java: "io.cucumber:cucumber-java8:${cucumberVersion}",
                            junit: "io.cucumber:cucumber-junit:${cucumberVersion}"
                    ],
                    junit: "junit:junit:${junitVersion}",
                    assertj: "org.assertj:assertj-core:${assertJVersion}"
            ]
    ]
}

And here is my build.gradle


defaultTasks 'clean', 'test', 'aggregate'

def cucumberVersion = "6.0.0-RC1"

repositories {
    mavenCentral()
    jcenter()
}
buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath("net.serenity-bdd:serenity-gradle-plugin:2.2.2")

    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'net.serenity-bdd.aggregator'
apply from: "$rootDir/gradle/libraries.gradle"

sourceCompatibility = 1.8
targetCompatibility = 1.8

configurations.all {
    resolutionStrategy {
        force "io.cucumber:cucumber-core:${cucumberVersion}"
    }
}

dependencies {
    implementation libs.logback

    testImplementation libs.test.cucumber.java,
            libs.test.cucumber.junit,
            libs.test.serenity.core,
            libs.test.serenity.screenplay,
            libs.test.serenity.junit,
            libs.test.serenity.screenplayWebdriver,
            libs.test.serenity.cucumber,
            libs.test.junit,
            libs.test.assertj
}

test {
    testLogging.showStandardStreams = true
    systemProperties System.getProperties()
}

gradle.startParameter.continueOnFailure = true

test.finalizedBy(aggregate)

I am using java 1.8 and gradle version 5.4

wakaleo commented 4 years ago

Use the serenity-cucumber-starter and Cucumbet 5 instead.

arpitsinghmrt commented 4 years ago

Hey @wakaleo thanks for the quick response, I tried your suggestion but now I am getting the following exception:

java.lang.NoClassDefFoundError: io/cucumber/core/eventbus/EventBus
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
    at java.lang.Class.getConstructor0(Class.java:3075)
    at java.lang.Class.getConstructor(Class.java:1825)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
    at org.junit.internal.requests.ClassRequest.createRunner(ClassRequest.java:28)
    at org.junit.internal.requests.MemoizingRequest.getRunner(MemoizingRequest.java:19)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:78)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
    at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: io.cucumber.core.eventbus.EventBus
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    ... 41 more
wakaleo commented 4 years ago

Are you trying to use Cucumber 6?

arpitsinghmrt commented 4 years ago

No, I am using Cucumber5

this is my libraries.gradle

ext{
    slf4jVersion = '1.7.7'
    serenityCoreVersion = '2.2.0'
    serenityCucumberVersion = '2.2.0'
    junitVersion='4.12'
    assertJVersion='3.8.0'
    logbackVersion='1.2.3'
    cucumberVersion = '4.8.0'

    libs = [
            slf4jApi: "org.slf4j:slf4j-api:$slf4jVersion",
            logback: "ch.qos.logback:logback-classic:${logbackVersion}",

            test: [
                    serenity: [
                            core: "net.serenity-bdd:serenity-core:${serenityCoreVersion}",
                            junit: "net.serenity-bdd:serenity-junit:${serenityCoreVersion}",
                            screenplay: "net.serenity-bdd:serenity-screenplay:${serenityCoreVersion}",
                            screenplayWebdriver: "net.serenity-bdd:serenity-screenplay-webdriver:${serenityCoreVersion}",
                            cucumber: "net.serenity-bdd:serenity-cucumber5:${serenityCucumberVersion}",
                    ],
                    cucumber: [
                            java: "io.cucumber:cucumber-core:${cucumberVersion}",
                            java: "io.cucumber:cucumber-java8:${cucumberVersion}",
                            junit: "io.cucumber:cucumber-junit:${cucumberVersion}"
                    ],
                    junit: "junit:junit:${junitVersion}",
                    assertj: "org.assertj:assertj-core:${assertJVersion}"
            ]
    ]
}

and this is my build.gradle

version '1.0-SNAPSHOT'

defaultTasks 'clean', 'test', 'aggregate'

repositories {
    mavenLocal()
    jcenter()
}
buildscript {
    repositories {
        jcenter()
        mavenLocal()
    }
    dependencies {
        classpath("net.serenity-bdd:serenity-gradle-plugin:2.2.0")

    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'net.serenity-bdd.aggregator'
apply from: "$rootDir/gradle/libraries.gradle"

sourceCompatibility = 1.8
targetCompatibility = 1.8

configurations.all {
    resolutionStrategy {
        force "io.cucumber:cucumber-core:${cucumberVersion}"
    }
}

dependencies {
    compile libs.logback

    testCompile libs.test.cucumber.java,
            libs.test.cucumber.junit,
            libs.test.serenity.core,
            libs.test.serenity.screenplay,
            libs.test.serenity.junit,
            libs.test.serenity.screenplayWebdriver,
            libs.test.serenity.cucumber,
            libs.test.junit,
            libs.test.assertj
}

test {
    testLogging.showStandardStreams = true
    systemProperties System.getProperties()
}

gradle.startParameter.continueOnFailure = true

test.finalizedBy(aggregate)
wakaleo commented 4 years ago

It’s a version conflict, make sure your cucumber versions correspond to the serenity ones or let serenity define the dependencies

arpitsinghmrt commented 4 years ago

Hey @wakaleo, that worked. Thanks for your help :)

emaninder commented 4 years ago

Hey @wakaleo, that worked. Thanks for your help :)

can you please share what worked for you. I still run into issues.

nvm, got it working.

gururajadg74 commented 3 years ago

Hey @wakaleo @arpitsinghmrt , I am also facing the same issue ..please help out.

java.lang.NoClassDefFoundError: cucumber/runner/EventBus at java.base/java.lang.Class.getDeclaredConstructors0(Native Method) at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3215) at java.base/java.lang.Class.getConstructor0(Class.java:3420) at java.base/java.lang.Class.getConstructor(Class.java:2165) at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104) at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70) at org.junit.internal.requests.ClassRequest.createRunner(ClassRequest.java:28) at org.junit.internal.requests.MemoizingRequest.getRunner(MemoizingRequest.java:19) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:90) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:76) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:49) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:526) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210) Caused by: java.lang.ClassNotFoundException: cucumber.runner.EventBus at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ... 18 more

Thanks Guru

wakaleo commented 3 years ago

NoClassDefFoundError is a version conflict - check the dependency versions in your gradle build.

BriceGestas commented 2 years ago

Hey @gururajadg74,

I encoutered a similar issue than yours

java.lang.NoClassDefFoundError: io/cucumber/core/eventbus/EventBus
    at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3137)
    at java.base/java.lang.Class.getConstructor0(Class.java:3342)
    at java.base/java.lang.Class.getConstructor(Class.java:2151)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
    at org.junit.internal.requests.ClassRequest.createRunner(ClassRequest.java:28)
    at org.junit.internal.requests.MemoizingRequest.getRunner(MemoizingRequest.java:19)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: java.lang.ClassNotFoundException: io.cucumber.core.eventbus.EventBus
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 15 more

And this is not a conflict version I guess

    <properties>
        <junit.version>4.13.2</junit.version>
        <it.cucumber.version>7.1.0</it.cucumber.version>
    </properties>
    <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${it.cucumber.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-spring</artifactId>
            <version>${it.cucumber.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${it.cucumber.version}</version>
            <scope>test</scope>
        </dependency>

Did you figured this out ?

wakaleo commented 2 years ago

This is a version conflict. https://github.com/serenity-bdd/serenity-core#what-is-the-latest-stable-version-i-should-use

BriceGestas commented 2 years ago

Hey @wakaleo,

I don't use serenity in my project...