Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SBT should default the current project directory as the working directory of forked runs #3892

Open
er1c opened this Issue Jan 17, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@er1c
Copy link

er1c commented Jan 17, 2018

I have a multi-project sbt file that I recently added the fork in (Compile, run) := true option on.

One of the first issues that popped up was the process wouldn't read a local file "localdir/localfiles.txt" - basically the working directory wasn't set to the project directory. This was easily fixed by manually specifying a working directory such as baseDirectory in (Compile, run) := file(".")

I would expect this to be a default behavior, rather than needing to be explicit. IntelliJ recently (in the last year or two?) also added a "Use project home as compile server working directory" which is the same/similar behavior I would expect.

an sbt "project subproject" "runMain foo.foo.App" will also use the top-level directory as the working directory

sbt version: 1.1.0

@dwijnand

This comment has been minimized.

Copy link
Member

dwijnand commented Jan 18, 2018

I'm not 100% certain if that should be the default, but as I was recently looking at how forking does things I think the change would have to be to change

https://github.com/sbt/sbt/blob/v1.1.0/main/src/main/scala/sbt/Defaults.scala#L752

to workingDirectory = Some((baseDirectory in ThisBuild).value)

@er1c

This comment has been minimized.

Copy link
Author

er1c commented Jan 18, 2018

If I understand how the code currently works, the subdirectory project is being set to the working directory? I can, of course, make an argument for that being the more "correct" behavior. But the behavior still "diverges" from the above example of running sbt "project subproject" "runMain foo.foo.App" and the top-level project directory will effectively be the working directory for a non-forked runMain

@dwijnand

This comment has been minimized.

Copy link
Member

dwijnand commented Jan 18, 2018

Yes I see what you mean. I'd have to look into the history of forking to see if it's possible to understand why this default was chosen.

Thanks for the analysis.

@mpollmeier

This comment has been minimized.

Copy link
Contributor

mpollmeier commented Feb 23, 2019

Thank you, this workaround helped me fix another long-lasting pain: in multi-projects, tests would run in either sbt or intellij. It works in both if your subproject/build.sbt specifies

Test/baseDirectory := (ThisBuild/Test/run/baseDirectory).value

Slightly more context: http://www.michaelpollmeier.com/2019/02/20/sbt-subprojects-tests-intellij

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.