gpt4 book ai didi

java - Gradle在运行的任务上设置了不正确的(意外的?)类路径

转载 作者:行者123 更新时间:2023-12-03 05:42:56 25 4
gpt4 key购买 nike

我的项目结构如下:

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

这完全符合预期。我定义了一个任务来运行 cucumber 测试,如下所示:
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目录。我期望classpath是:
<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进行编译解决了该问题。

关于java - Gradle在运行的任务上设置了不正确的(意外的?)类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51637372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com