Gradle application plugin: Modify workingDir property
Asked Answered
C

1

4

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?

Cataclinal answered 2/6, 2015 at 11:0 Comment(0)
C
6

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.

Cataclinal answered 2/6, 2015 at 11:0 Comment(2)
With gradle 7.3.3 (not sure since which version), I have to use tasks.run.get().workingDir = runningDirBhatt
A few gradle versions later, and none of this works anymore.Carranza

© 2022 - 2024 — McMap. All rights reserved.