Error: Could not find or load main class cucumber.api.cli.Main

27,544

The following script works in terms of proper configuration but fails since there are now features/test to check.

apply plugin: 'java'

repositories {
    mavenCentral()
}

configurations {
    cucumber
}

dependencies {
    cucumber 'info.cukes:cucumber-java:1.2.2'
}

task runCucumber(type: JavaExec) {
    main = "cucumber.api.cli.Main"
    args += ['-f', 'html:build/reports/cucumber/', '-f', 'json:build/reports/cucumber/report.json', '--glue', 'com.waze.testing.cucumber', 'src/main/resources/features'
             , '--tags', '~@ignore', '--tags', '~@preRelease', '--tags', '@advil']
    systemProperties['http.keepAlive'] = 'false'
    systemProperties['http.maxRedirects'] = '20'
    ignoreExitValue = true
    classpath = configurations.cucumber
}

This is how JavaExec classpath should be modified.

Share:
27,544
Elad Benda2
Author by

Elad Benda2

Updated on July 05, 2022

Comments

  • Elad Benda2
    Elad Benda2 almost 2 years

    I try to run this gradle task

    task runCucumber(type: JavaExec) {
        main = "cucumber.api.cli.Main"
        args += ['-f', 'html:build/reports/cucumber/', '-f', 'json:build/reports/cucumber/report.json', '--glue', 'com.waze.testing.cucumber', 'src/main/resources/features'
                 , '--tags', '~@ignore', '--tags', '~@preRelease', '--tags', '@advil']
        systemProperties['http.keepAlive'] = 'false'
        systemProperties['http.maxRedirects'] = '20'
        ignoreExitValue = true
    }
    

    and get this error:

    Error: Could not find or load main class cucumber.api.cli.Main

    why is that? I can find it in the included cucumber jar.

    Edit

    I already have this task that runs successfully:

    mainClassName = "cucumber.api.cli.Main"
    
        run {
            args += ['-f', 'html:build/reports/cucumber/', '-f', 'json:build/reports/cucumber/report.json', '--glue', 'com.waze.testing.cucumber', 'src/main/resources/features'
                     , '--tags', '~@ignore', '--tags', '~@preRelease']
            systemProperties['http.keepAlive'] = 'false'
            systemProperties['http.maxRedirects'] = '20'
        }