In sbt, if we execute package
, a jar file will generated at target/scala-2.12/XXX.jar
. But I want to put the jar file at myDirectory/XXX.jar
. How can I make this?
The target/
part of the default path is defined by the target
setting key and the scala-2.12/
part is defined by the crossTarget
setting (because you may cross-compile for different version of Scala). So a simple solution is to add this to your build.sbt
:
crossTarget := baseDirectory.value / "myDirectory"
Now if you call package
task from sbt, you will get all files the myDirectory/
directory including the jar, classes and other stuff that normally goes to target/scala-2.12/
.
If you want to change only the jar's location, you can change the artifactPath
setting. But you should set it in the right scope and with the jar filename:
artifactPath in packageBin in Compile := baseDirectory.value / "myDirectory" / "XXX.jar"
// if you're using sbt 1.1+, you can also write like this:
Compile/packageBin/artifactPath := ...
This can easily get more complicated and messy if you have a non-trivial setup. So check the sbt sources to learn how artifactPath
setting is actually defined and read about artifacts in the sbt documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With