gradle/gradle

The application plugin's run task should not change the working directory

sschuberth opened this issue · 2 comments

Gradle 4.9 added support for passing arguments to JavaExec tasks. By default, JavaExec tasks change the working directory to the project directory. However, this default behavior is confusing when using the application plugin's run task (which is a JavaExec task) and passing relative file paths as part of the arguments.

Expected Behavior

Assume a multi-project and a directory structure like

+ $HOME
  |
  + development (contains root build.gradle file and input-file.txt file)
     |
     + app (contains app build.gradle file)
     |
     + lib (contains lib build.gradle file)

When running an application like

cd ~/development
./gradlew app:run --args="--input input-file.txt"

I would expect the application to look for input-file.txt at ~/development/input-file.txt.

Current Behavior

The application looks for input-file.txt at ~/development/app/input-file.txt.

Context

Now that arguments can be passed to JavaExec tasks, it's convenient to use that feature as a drop-in replacement for calling the start scripts that can be generated by the application plugin. However, currently relative file paths need to be adjusted to take the implicit change of the working directory into account.

Steps to Reproduce (for bugs)

I wouldn't necessarily consider this to be a bug, but rather an ask for a change in behavior to increase convenience.

Your Environment

------------------------------------------------------------
Gradle 4.9
------------------------------------------------------------

Build time:   2018-07-16 08:14:03 UTC
Revision:     efcf8c1cf533b03c70f394f270f46a174c738efc

Kotlin DSL:   0.18.4
Kotlin:       1.2.41
Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM:          1.8.0_162 (Oracle Corporation 25.162-b12)
OS:           Windows 10 10.0 amd64
stale commented

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you're interested in how we try to keep the backlog in a healthy state, please read our blog post on how we refine our backlog. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution.

stale commented

This issue has been automatically closed due to inactivity. If you can reproduce this on a recent version of Gradle or if you have a good use case for this feature, please feel free to to let know so we can reopen the issue. Please try to provide steps to reproduce, a quick explanation of your use case or a high-quality pull request.