How do I specify a custom directory layout for an sbt
-based project? I've been looking at the online sbt
material, but I'm struggling to find this information...
What I did find in the documentation were the default locations:
src/main/scala
and src/main/java
src/test/scala
and src/test/java
src/main/resources
and src/test/resources
lib/
How do I override these in the build.sbt
file?
My project structure is currently as follows:
[workspace]/sandbox-scala/src/sbt/myFirst/
[workspace]/java-lib/common/lib/
Any help appreciated.
Create or open your sbt project. In the Project tool window, in the source root directory, locate the build. properties file and open it in the editor. In the editor explicitly specify the version of sbt that you want to use in the project.
The libraryDependencies key Most of the time, you can simply list your dependencies in the setting libraryDependencies . It's also possible to write a Maven POM file or Ivy configuration file to externally configure your dependencies, and have sbt use those external configuration files.
sbt. Therefore, this folder contains all the files needed for building build. sbt. project/build. properties — this file contains build definition of build.
The project folder contains sbt configurations and settings, while src contains all your source code. sbt creates the target folder after you compile your code; it includes the JVM bytecode of your application.
One can override a number of sbt's default directory locations. Here's an example that overrides the directory where sbt expects to find "unmanaged" dependencies/jar files:
unmanagedBase := baseDirectory.value / "custom-jars-directory"
(More examples related to depndencies in the sbt documentation.)
You can also configure the directories as specific to a particular "task"... E.g., to set the directory where test-case source code is, try:
scalaSource in Test := { (baseDirectory in Test)(_ / "test") }.value
And then your core application source code could be somewhere else, say under src/
:
scalaSource in Compile := { (baseDirectory in Compile)(_ / "src") }.value
NOTE: For older versions of sbt
you may need the following (now-deprecated) syntax:
unmanagedBase <<= baseDirectory { base => base / "custom-jars-directory" }
scalaSource in Compile <<= (baseDirectory in Compile)(_ / "src")
This syntax will not work in newer versions of sbt
(since 0.13.13, I believe).
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