toconn
toconn

Reputation: 874

'Gradle cucumber' With testImplementation Not Working

I am building a simple test app that uses cucumber. Unfortunately 'gradle cucumber' throws errors when I try to run it. However everything runs fine when I change testImplement to the deprecated testCompile in build.gradle. Is this expected behaviour? What would I have to do to get cucumber to run using testImplementation?

build.gradle:

dependencies {
    testImplementation 'io.cucumber:cucumber-java:4.2.0'
    testImplementation 'io.cucumber:cucumber-junit:4.2.0'
}

configurations {
    cucumberRuntime {
        extendsFrom testRuntime
    }
}

task cucumber() {
    dependsOn assemble, compileTestJava
    doLast {
        javaexec {
            main = "cucumber.api.cli.Main"
            classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'pretty', '--glue', 'gradle.cucumber', 'src/test/resources']
        }
    }
}

Result (Error):

> Task :cucumber FAILED
Error: Could not find or load main class cucumber.api.cli.Main
Caused by: java.lang.ClassNotFoundException: cucumber.api.cli.Main

build.gradle:

dependencies {
    testCompile 'io.cucumber:cucumber-java:4.2.0'
    testCompile 'io.cucumber:cucumber-junit:4.2.0'
}
...

Result (Works):

> Task :cucumber
No features found at [src/test/resources]

0 Scenarios
0 Steps

Can someone explain what is going on here? Any help is greatly appreciated!

Upvotes: 2

Views: 2344

Answers (1)

lance-java
lance-java

Reputation: 27958

See here which says that testRuntime is deprecated

The compile, testCompile, runtime and testRuntime configurations inherited from the Java plugin are still available but are deprecated

I think it should be

configurations {
    cucumberRuntime {
        extendsFrom testImplementation
    }
}

Upvotes: 6

Related Questions