I'm making a little web project with scala, scalate and jade templates. The problem is when i'm changing .scala or .conf files, sbt automatically recompiles them and reloads project, but it doesn't do it when i'm changing my .jade files. All my templates lies under the pages/ folder in src/main and it is added on the project classpath, also i've added this line to Build.scala file in project/ folder:
unmanagedSourceDirectories <+= (sourceDirectory)(_ / "pages")
Just had a similar problem. You should change your line in the scala build file on this one:
unmanagedResourceDirectories in Compile <+= (baseDirectory)(_ / "src" / "main" / "pages")
This should solve your problem.
Related
My structure of scala project is pretty simple:
/someApp
/scala
/project
Dependencies.scala
...
/main
...
/test
MyTest.scala
/target
...
build.sbt
Now, let's consider:
sbt> testOnly *MyTest
It recompiles MyTest.scala and executes it as I expect. However, when I introduce changes to build.sbt or project/Dependencies.scala it ignores these changes.
Could someone explain me and understand why does it happen? The sbt seems to be one huge mystery...
To include changes made to .sbt files or .scala files under the project folder, you'll need to run the reload command within the sbt shell.
You can also force sbt to reload each time it detects a change in these files by adding this line to your build.sbt:
Global / onChangedBuildSource := ReloadOnSourceChanges
When creating an SBT scala project in ItelliJ, it wants me to put all source code in the src/main/scala folder of the project folder. However, I want to put the source code somewhere else independent or particular projects, build-tools, IDEs, etc.
How do I tell it to get the source from arbitrary locations?
You can use the following settings to change the location where SBT looks for your Scala sources:
// Change Scala source directory. Default is:
// scalaSource in Compile := baseDirectory.value / "src" / "main" / "scala"
scalaSource in Compile := file("<Path to your sources...>")
// Change Scala test source directory. Default is:
// scalaSource in Test := baseDirectory.value / "src" / "test" / "scala"
scalaSource in Test := file("<Path to your test sources...>")
For further information (including how to specify other source, library and resource directories), refer to the official SBT documentation for customizing paths.
How do I add additional file to classpath which is not java or scala file using SBT configuration ?
My source folder is defined like this
javaSource in Compile := baseDirectory.value / "src"
I have jawr.properties in the root of my /src folder. I'd like this file to be copied to WEB-INF/classes of my packaged app. I tried changing filter to
includeFilter in (Compile, unmanagedSources) := "*.java" || "*.scala" || "jawr.properties",
But it fails on sbt compile because it tries to compile it as java file.
I'm on SBT 0.13.6
The philosophy of SBT is to work by convention (and not by configuration) as much as possible. So the most straightforward solution, in many cases, isn't to look for the correct setting to tell SBT where your files are... But rather to figure out where SBT already expects to find them. You can check this page of the "getting started with SBT" guide for the basics.
For resource files that needs to be packaged together with compiled classes, the default directory is src/main/resources (a convention borrowed from Maven, like most of SBT's default directory structure). Similarly, files in src/test/resources are added to the classpath but only during tests.
If, for some reason, you want to use non-standard directories, you will want to have a look at this page of the documentation. For resources, the key to modify is resourceDirectory:
// resources in `resources` instead of `src/main/resources` :
resourceDirectory in Compile := baseDirectory.value / "resources"
// test resources in `test-resources` instead of `src/test/resources` :
resourceDirectory in Test := baseDirectory.value / "test-resources"
You want it be an unmanaged resource (not source)
unmanagedResourceDirectories in Compile := Seq(baseDirectory.value / "src")
includeFilter in unmanagedResources := "jawr.properties"
How do I configure an extra folder for sbteclipse to include? I have a default sbt directory layout with an additional it/scala folder. I want that folder to be included in the generated .project and .classpath files, but I don't know how to do that....
You can achieve this for example by adding something like the following to your build.sbt:
unmanagedSourceDirectories in Compile <++= baseDirectory { base =>
Seq(
base / "some/subdir/src"
)
}
For details of the relation between unmanaged-sources, unmanaged-source-directories and scala-source you might want to check the documentation. After exporting the eclipse project from sbt, you should find a corresponding entry in your .classpath file, like:
<classpathentry output="target/scala-2.9.1/classes" path="some/subdir/src" kind="src"></classpathentry>
there can be case in which you may just want to add a folder say conf to the eclipse classpath which contains configurations required at runtime. Below is the trick -
unmanagedJars in Compile ++= {
val confBase = (baseDirectory.value ** "conf")
confBase.classpath
}
if you want to add, e.g., the folder src/folderXYZ, then add to build.sbt:
Compile / unmanagedSourceDirectories += baseDirectory.value / "src/folderXYZ"
I'm having quite a few troubles pointing at a custom directory for Scala source-files in SBT.
I would like sbt to compile scala-files from a given directory instead of the regular src/main/scala directory.
I have tried both defining a .sbt and .scala project files, setting baseDirectory, scalaSource (and scalaSource s in the .scala file). I've also toyed around with everything from system-absolute to relative paths but nothing seems to work. It cannot locate any .scala file under the specified directory.
What are the proper ways to handle this?
Try this in build.sbt:
scalaSource in Compile <<= (sourceDirectory in Compile)(_ / "foo")
This will result in a directory src/main/foo for Scala sources. If you want to use some arbitrary directory, go for this:
scalaSource in Compile := file("/Users/heiko/tmp")
Update answer for SBT 0.13.13 ->
sourceDirectory in Compile := (baseDirectory( _ / "foo" )).value
And to add a source directory (instead of just replacing it) also for SBT 0.13.13 ->
unmanagedSourceDirectories in Compile += (baseDirectory( _ / "foo" )).value