Get rid of main-{scalaVersion}-Directories in sbt - scala

I've changed the default src directory according to: http://www.scala-sbt.org/0.13.2/docs/Howto/defaultpaths.html
to:
scalaSource in Compile := baseDirectory.value / "src/main"
javaSource in Compile := baseDirectory.value / "src/main"
scalaSource in Test := baseDirectory.value / "src/test"
javaSource in Test := baseDirectory.value / "src/test"
resourceDirectory in Compile := baseDirectory.value / "res"
resourceDirectory in Test := baseDirectory.value / "res/test"
Now whenever intellij/idea reloads it adds back main-2.11 and test-2.11 folders.
I want to get rid of those, but I've not found a way for now. Any ideas?
edit: I've already deleted the whole .idea and other folders for IntelliJ and re-imported the project with the .sbt file. Still no luck. On every startup or change of the .sbt these annoying folders are re-created. Grrr!

The problem might rather lie with sbt. If you open sbt console and enter
show sourceDirectories
the result might still include the scala-2.11 folders.
If so the following lines would fix that:
sourceDirectories in Compile <<= (sourceDirectories in Compile) { dirs =>
dirs.filterNot(_.absolutePath.endsWith("-2.11"))
}
sourceDirectories in Test <<= (sourceDirectories in Test) { dirs =>
dirs.filterNot(_.absolutePath.endsWith("-2.11"))
}

Related

Is it possible to have in SBT a Test Fixture source folder?

Reading the following SBT documentation:
https://www.scala-sbt.org/1.x/docs/Appending-Values.html
And also
https://www.scala-sbt.org/1.x/docs/Classpaths.html
I can get on how to create a test source folder with only utils classes to be consume both by the tests in the same project and in all other projects that depend on it.
I tried the following but got compilation issues:
Test / sourceDirectories := Seq( baseDirectory.value / "testFixtures", baseDirectory.value / "test")
And also the following but this time sbt does not find any tests in the project:
sourceDirectory in Test := baseDirectory.value / "test"
Test / unmanagedSourceDirectories += baseDirectory.value / "testFixtures"
any idea ?
Thanks

SBT + IntellIj Not Recognising My Integration Test Directory

I am trying to set up integration test folder for my project. So in I added the following to my SBT build definition:
.configs(IntegrationTest)
.settings(
Defaults.itSettings,
IntegrationTest / dependencyClasspath :=
(IntegrationTest / dependencyClasspath).value ++ (Test / exportedProducts).value,
Keys.fork in IntegrationTest := false,
unmanagedSourceDirectories in IntegrationTest := (baseDirectory in IntegrationTest)(base => Seq(base / "it")).value,
resourceDirectory in IntegrationTest := baseDirectory.value / "it/resources",
parallelExecution in IntegrationTest := false
)
The folder structure looks like:
src
|-it
|-scala
But if I start an sbt session and do it:test it does not pick up any of the tests. Also Intellij is not marking the it directory green as well which is the colour of test folders. How do I set this up?
It is most likely that this line is incorrect:
unmanagedSourceDirectories in IntegrationTest := (baseDirectory in IntegrationTest)(base => Seq(base / "it")).value
In majority of the cases, if you are not doing any exotic custom integration setup, the default settings that come with sbt are fine. See this post.

How can I make `javaSource` directory different from `sourceDirectory` / main / java?

I have old and big Java project in which I want to start using Scala. All Java sources are stored in /src. Unfortunately I cannot move them to standard /src/main/java directory because there are tons of old Ant scripts and etc.
So my goal is to have new Scala source and resources in /srcnew and keep Java stuff in /src. So I wrote following in build.scala
sourceDirectory := baseDirectory.value / "srcnew",
javaSource := baseDirectory.value / "src",
And it doesn't work :) SBT doesn't see source in javaSource at all.
What am I missing ?
These are the examples from "Customizing paths" in the SBT docs:
scalaSource in Compile := baseDirectory.value / "src"
scalaSource in Test := baseDirectory.value / "test-src"
javaSource in Compile := baseDirectory.value / "src"
javaSource in Test := baseDirectory.value / "test-src"
So in your case it would be
sourceDirectory in Compile := baseDirectory.value / "srcnew"
javaSource in Compile := baseDirectory.value / "src"

Setting `unmanagedResourceDirectories` breaks deployment of resources from `resourceDirectory`

I have a little bit odd setup. My Java sources are located at
/src
There are .properties files next to some Java classes. I want them to be packaged to final jar.
Scala sources and resources follow SBT convention and are located at
/srcnew/main/[scala|resources]
Here is how my build.scala looks like
sourceDirectory := baseDirectory.value / "srcnew",
unmanagedResourceDirectories in Compile := Seq(baseDirectory.value / "src"),
includeFilter in unmanagedResources := "*.properties",
javaSource in Compile := baseDirectory.value / "src",
Even though resourceDirectory still points to /srcnew/main/resources resources don't make it to final jar (built with sbt-assembly).
I also tried
unmanagedResourceDirectories := Seq(baseDirectory.value / "src", baseDirectory.value / "srcnew/main/resources"),
and surprisingly it doesn't help either.
Turned out that problem was in line
includeFilter in unmanagedResources := "*.properties"
instead it should be
includeFilter in unmanagedResources := ((includeFilter in unmanagedResources).value || "*.properties") -- "*.java",
the only thing I don't understand is why filter on unmanagedResources affects resourceDirectory. Does anyone know ?

How do I get sbt 0.10.0 to compile files in a subdirectory?

I have a build.sbt file in my project root.. all my source files live in the subdirectory src (and src/irc, src/xmpp).
Here is my build.sbt
name := "mrtoms"
organization := "chilon"
scalaVersion := "2.9.0"
version := "0.1"
libraryDependencies ++= Seq("commons-httpclient" % "commons-httpclient" % "3.1")
crossPaths := false
scalaHome := Some(file("/usr/share/scala"))
target := file("project/target")
sourceDirectory := file("src")
mainClass := Some("org.chilon.mrtoms.MrToms")
However sbt always just makes an empty jar file.
I tried putting build.sbt inside the "src" directory but then it missed out all the scala files in subdirectories of "src".
Seems that you need to provide path relative to the base directory. This should work for you (it replaces sourceDirectory := file("src")):
scalaSource in Compile <<= baseDirectory(_ / "src")
Some more information you can find in this thread:
http://groups.google.com/group/simple-build-tool/browse_thread/thread/095e87247d146fa7?fwc=1
If you want to replace the default convention then you need to override both scala and java source locations
scalaSource in Compile <<= baseDirectory(_ / "src")
javaSource in Compile <<= baseDirectory(_ / "src")