Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify a custom directory layout for an sbt project?

Tags:

build

sbt

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:

  • Sources in the base directory
  • Sources in src/main/scala and src/main/java
  • Tests in src/test/scala and src/test/java
  • Data files in src/main/resources and src/test/resources
  • Unmanaged jar-files in lib/

How do I override these in the build.sbt file?

My project structure is currently as follows:

  • Source in: [workspace]/sandbox-scala/src/sbt/myFirst/
  • Libraries in: [workspace]/java-lib/common/lib/

Any help appreciated.

like image 766
dutoitns Avatar asked Mar 18 '13 11:03

dutoitns


People also ask

How do I specify sbt?

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.

How do we specify library dependencies in sbt?

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.

What is .sbt folder?

sbt. Therefore, this folder contains all the files needed for building build. sbt. project/build. properties — this file contains build definition of build.

What does the src folder contain in an sbt project?

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.


1 Answers

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).

like image 164
Chris W. Avatar answered Sep 27 '22 20:09

Chris W.