These are chat archives for sbt/sbt

25th
Feb 2017
Brian Topping
@briantopping
Feb 25 20:25
Question: What's the best way to build a secondary artifact that has a subset of classes that are on the source path?
This is probably so easy it's not even called out in the documentation
OlegYch
@OlegYch
Feb 25 20:28
use a separate project
Brian Topping
@briantopping
Feb 25 20:31
Yes, I guess I want to use a separate project with includeFilter?
just pawing through Keys.scala
Paul Draper
@pauldraper
Feb 25 21:19
Yes.
OlegYch
@OlegYch
Feb 25 21:23
you just a separate project as far as i can see
*need
with the subset of sources in its source path
Brian Topping
@briantopping
Feb 25 21:27
ty :)
Brian Topping
@briantopping
Feb 25 21:33
    includeFilter in Compile := new SimpleFileFilter(file => {
      file.toPath.startsWith(sourceDirectory.value.toPath.resolve("main/scala/example/client"))
    }
It kind of works, but not
[error] source file '/Users/brian/project/src/main/scala/example/client' could not be found
Brian Topping
@briantopping
Feb 25 21:39
I don't understand why it's thinking that's a source file, it's a directory that I am comparing to.
Douglas Alan
@nessus42
Feb 25 21:42

Hi. I'd like to use "sbt run" to make "scripts" in Scala. I.e., like I might do with Python or bash, etc. One requirement is that they must behave like any normal Unix program without any weirdness to them. I've got it mostly working. E.g. I figured out how to silence the info messages that usually get output and how to get rid of the "[succeeded]" messages at the end. I think I only have a single remaining issue:

If my script terminates with, for instance, sys.exit(5), then my script does not terminate properly. First of all, I get this error message:

Exception: sbt.TrapExitSecurityException thrown from the UncaughtExceptionHandler in thread "run-main-0"
java.lang.RuntimeException: Nonzero exit code: 5
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code: 5
[error] Total time: 0 s, completed Feb 25, 2017 4:38:30 PM

Some of that goes to stdout and some of that goes to stderr, which is also not right.

Finally, the exit status of the "sbt run" invocation is 1, rather than 5.

Is there a way that I can get rid of all of this unfortunate output to stdout and stderr, and to have "sbt run" exit with status 5 rather than 1.

As a point of comparison, if I make an assembly, sys.exit() works perfectly. Also sys.exit() works with the Ammonite script runner. (Unfortunately Ammonite has some other issues that are making it less than ideal for me at the moment.)

Douglas Alan
@nessus42
Feb 25 21:49

I just found the answer on Stack Overflow:

It's to put trapExit := false in the build.sbt.

I didn't find it previously because the question wasn't quite the same as mine and the answer was unaccepted with a score of 0!

Brian Topping
@briantopping
Feb 25 21:49
Vote it up! :)
I always add comments to answers like that...
Douglas Alan
@nessus42
Feb 25 21:50
I think I need to actually post a question that is closer to mine, and then answer it msyelf. The person asking the question didn't care about getting the correct exit status. He just didn't want the ugly error messages. But I'll vote up that answer too. Thanks for the suggestion!
Brian Topping
@briantopping
Feb 25 21:55
SO surprises me sometimes with good content :)
It's too bad gitter doesn't have threading and the ability to open and close threads depending on if one found a resolution.
(i just thought that up, full of good ideas lol)
Brian Topping
@briantopping
Feb 25 22:10
Oh, I get it, somehow I replaced the existing filter and mine caught the directory and accepted it.
magic
Brian Topping
@briantopping
Feb 25 22:42
oh gnarly... I didn't notice that only the client was building now:
lazy val root = Project("search-root", file("."))
  .aggregate(`server-mod-search`, `server-mod-search-client`)

lazy val `server-mod-search` = Project("server-mod-search", file("."))

lazy val `server-mod-search-client` = Project("server-mod-search-client", file("."))
seems like the file location is some kind of key and There Can Be Only One
Brian Topping
@briantopping
Feb 25 22:51
I guess that makes some sense, there needs to be different target directories at the very least. Hrm.