Gradle application plugin: Modify workingDir property

空扰寡人 提交于 2019-12-07 11:58:54

问题


I simply want to modify the directory where the program is run. Normally, it's run from the project root, which annoys me a little bit, because testing the program out can be quite annoying, since my program generates files and folders where it is being run.

A JavaExec task has a property called JavaExec#workingDir, which would be this exact property I wanted to modify to something different of my choice.

My question is: How do I modify the gradle run task in order to access this property?


回答1:


You can access a property of a task by using tasks.<TaskToModify>.property = YourValue.

So, in this case, you would have to do this:

File runningDir = new File('build/run/')
runningDir.mkdirs()
tasks.run.workingDir = runningDir

The File#mkdirs() call is neccessary, since if the directories do not exist, the call to your system-dependent java executable will cause a error.



来源:https://stackoverflow.com/questions/30594196/gradle-application-plugin-modify-workingdir-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!