gpt4 book ai didi

java - 如何告诉 gradle run 使用自定义工作目录?

转载 作者:行者123 更新时间:2023-12-01 19:51:58 24 4
gpt4 key购买 nike

我想用gradle run执行一个java类带有自定义工作目录。根据我对文档的阅读,简单地做 gradle run -PworkingDir=<mydir>应该可以解决问题,但它不起作用,工作目录仍然是项目目录。

我正在使用gradle run作为简单测试脚本的一部分。

最佳答案

来自Need a simple way to set working directory for Run and Debug :

It is technically possible to do this by creating a custom run task like this:

task run(dependsOn: classes, type: JavaExec) {
main = project.hasProperty('mainClass') ? project.mainClass : ''
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in

if (project.hasProperty('runWorkingDir')) {
workingDir = new File(project.runWorkingDir)
}
}

In this case you can specify a -PrunWorkingDir=<my-working-dir>. The obvious caveat of this is that you have to do this for debug as well and you may have to specify the working directory again for "Run Single" and "Debug Single" as well.

However, instead of adding a project property for working directory, I'm thinking allowing adding a set of variables. This case you only have to specify the working directory once and then you only need to write "-PrunWorkingDir=${run-working-dir}". Also, the built-in run task could support the "runWorkingDir" property.

关于java - 如何告诉 gradle run 使用自定义工作目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59080111/

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