java - Gradle 在运行任务上设置了不正确(意外?)的类路径
问题描述
我的项目结构是这样的:
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:
有趣的是,build
在项目根目录下根本没有生成目录。如何设置类路径以便可以找到类和资源?
解决方案
好的,原来问题不在于 Gradle,而在于 IntelliJ IDEA。IDEA 覆盖了标准 gradle 路径,并将输出保存在与 gradle 预期不同的路径中。然后,当下一个 gradle 任务运行时,输出不存在。直接使用gradle而不是IDEA编译解决了这个问题。
推荐阅读
- javascript - 使用 vee-validate 离开页面前提示
- swift - Swift 顺序执行函数
- javascript - 节点进程不以猫鼬索引退出
- php - 无法使用 apache 从根 Centos 7 引用的 php 中的 scandir()
- javascript - Node.js 异步/等待模块导出
- oracle - 将 nls 日期格式传递给 SQL Loader 控制文件
- google-chrome - chrome 的 200 和 200 OK 有什么区别?
- meteor - 流星银河“部署失败”
- java - Twitter4j:Oauth 不起作用
- c# - 删除行并将行添加到 DataGridView 时创建的重复行