我的项目结构如下:
projectRoot
+-src
+-main
| +-java
| | +-package/java files go here
| +-resources
| +-config
| +-files go here
+-test
+-java
| +-package/java files go here
+-resources
+-config
| +-files go here
+-features
+-files go here
在构建此项目时,它将生成以下输出结构:
projectRoot
+-out
+-production
| +-classes
| | +-package/classes in here
| +-resources
| +-config
| +-files in here
+-test
+-classes
| +-package/classes in here
+-resources
+-config
| +-files in here
+-features
+-files in here
一切如预期。我定义了一个任务来运行黄瓜测试,如下所示:
task runCucumber() {
doLast {
javaexec {
main = "cucumber.api.cli.Main"
args += ['--plugin', 'pretty', '--plugin', 'html:out/reports/cucumber/', '--plugin', 'json:out/reports/cucumber/report.json',
'--glue', 'com.example.mypackage.cucumber', 'classpath:features'
, '--tags', 'not @ignore']
systemProperties['http.keepAlive'] = 'false'
systemProperties['http.maxRedirects'] = '20'
systemProperties['env'] = System.getProperty("env")
systemProperties['envType'] = System.getProperty("envType")
classpath = configurations.cucumber + configurations.compile + configurations.testCompile + sourceSets.main.runtimeClasspath + sourceSets.test.runtimeClasspath
}
}
}
当我执行这个任务时,没有找到我的类,也没有功能。显然,这是由于类路径设置不正确。如果我用
--info
但是,我可以看到类路径是使用我指示的参数设置的,而不是
out
目录,它包含
build
目录。我希望课堂路径是:
<all dependencies>:/projectRoot/out/production/classses:/projectRoot/out/production/resources:/projectRoot/out/test/classes:/projectRoot/out/test/resources
然而,类路径包含以下内容:
<all dependencies>:/projectRoot/build/classes/java/main:/projectRoot/build/classes/java/test:
有趣的是,目录
建造
根本不是在项目根目录下生成的。如何设置类路径以便找到类和资源?