Java 错误:无法找到或加载主类cucumber.api.cli.Main

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28794397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 06:49:33  来源:igfitidea点击:

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

javaintellij-ideagradlecucumberbuild.gradle

提问by Elad Benda2

I try to run this gradle task

我尝试运行此 gradle 任务

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

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'
    }

采纳答案by Opal

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 JavaExecclasspath should be modified.

这是JavaExec应该如何修改类路径。