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"
Related
I am writing an sbt-plugin to abstract away some boilerplate.
Let's call it sbt-redux
then there is one more plugin sbt-assembly.
In this quest, my plugin(sbt-redux) needs to know about where the project ( Project which is using sbt-redux ) will create Uber jar using sbt-assembly and what will be the name of jar.
I tried adding sbt-assembly in plugins of sbt-redux, but for the obvious reasons it will not add dependencies in my src folder as it has limitations only in build.sbt.
I tried using .dependsOn(assembly) but still no luck.
So, How can I use other plugins into src?
P.S. Please let me know if the question is not clear.
There I found a solution and it is working for me.
If you want to read assembly's settings, you have to make sure your plugins depend on it. In your build.sbt file, you can add:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.7").
And then in your AutoPlugin implementation, you should override requires this way:
override def requires = super.requires && sbtassembly.AssemblyPlugin
After that, you'll have access to assembly settings and tasks.
Thanks to gpoirier.
To expand on the correct answer from #arglee, when you have a multi-module project, the addSbtPlugin line needs to be part of the .settings entries for the module that needs the dependency, like:
lazy val mod = (project in file("mod"))
.settings(
...,
addSbtPlugin( ... ),
libraryDependencies ++= Seq( ... ),
...
)
can a sbt sub project have its own project directory? or only the root project can project directory with .scala helper files for the build?. Below is my current build scructure. The /my-project/sub-projects/sub-project-1/build.sbt is not able to access objects defined in /my-project/sub-projects/sub-project-1/SubProjectHelper.scala.
/my-project
build.sbt
/projects
Helper.scala
sub-projects
sub-project-1
build.sbt
/projects
SubProjectHelper.scala
Update:
The below sbt definition in sub-project-1/build.sbt
lazy val localhost = (project in file(".")).settings (
name := """localhost""",
version := Common.version,
scalaVersion := Common.scalaVersion,
libraryDependencies ++= Common.dependencies,
libraryDependencies ++= Localhost.dependencies
)
is failing with the below error
libraryDependencies ++= Localhost.dependencies
^
sbt.compiler.EvalException: Type error in expression
at sbt.compiler.Eval.checkError(Eval.scala:384)
at sbt.compiler.Eval.compileAndLoad(Eval.scala:183)
at sbt.compiler.Eval.evalCommon(Eval.scala:152)
at sbt.compiler.Eval.evalDefinitions(Eval.scala:122)
at sbt.EvaluateConfigurations$.evaluateDefinitions(EvaluateConfigurations.scala:271)
at sbt.EvaluateConfigurations$.evaluateSbtFile(EvaluateConfigurations.scala:109)
at sbt.Load$.sbt$Load$$loadSettingsFile$1(Load.scala:712)
Common is defined in /my-project/projects/Common.scala and has no issues. But Localhost is defined in /my-project/sub-projects/sub-project-1/projects/SubProjectHelper.scala is not properly resolved in the sub-project-1 build.sbt
Yes, they can, and you even don't need to have sub-projects dir, just place sub-project-1 in my-project dir.
Usually (at least this is what scala/scala-seed.g8 ends up with) project subdirectory doesn't ends with an extra s like your directory structure.
You should rename projects to project.
The answer is no, unfortunately. As seen here
You cannot have a project subdirectory or project/*.scala files in the sub-projects. foo/project/Build.scala would be ignored.
I want to create a standalone version of my application and was wondering how i could exclude
an unmanaged *.jar file to be packaged. It's the "mariaDB4j-2.0-SNAPSHOT.jar" file I solely
use in tests which is about 56MB huge.
I tried to put the jar file into a custom directory 'test/lib'. Unfortunately, this did not exclude mariaDB4j from packaging.
unmanagedBase <<= baseDirectory { base => base / "test/lib" }
unmanagedJars in Test <<= unmanagedBase map { base => (base ** "mariaDB4j-2.0-SNAPSHOT.jar").classpath }
Any thoughts on this?
Cheers
Oliver
I think you want to add to the testing classpath.
Two things:
You can check out what's on the classpath using show test:fullClasspath to make sure your jar is on there. Using inspect test:fullClasspath will show you what the dependencies used for testing are.
I think you can directly add your jar to the classpath via:
fullClasspath in Test += Attributed.blank(baseDirectory.value / "test/lib/mariaDB4j-2.0-SNAPSHOT")
Hope that helps!
This works, but it looks a little overstated. Changing the base directory of the unmanaged dependencies, include the file to the test's and exclude it from compile.
unmanagedBase <<= baseDirectory { base => base / "test/lib" }
unmanagedJars in Test <<= unmanagedBase map { base => (base ** "mariaDB4j-2.0-SNAPSHOT.jar").classpath }
excludeFilter in unmanagedJars in Compile := "mariaDB4j-2.0-SNAPSHOT.jar"
excludeFilter in unmanagedJars in Compile ~= { _ || "mariaDB4j-2.0-SNAPSHOT.jar" }
don't use unmanaged dependencies
if you want to keep the jar in your source repository just use a file based maven repository in your source tree with
resolvers += "Private Maven Repository" at file(".").toURI.toURL+"/repository"
then mvn install MariaDB4j locally and copy resulting stuff from maven cache to $yourproject/repository
and use the dependency like a regular managed dependency
I have an external java project that my lift project depends on. I have been able to add the dependency to the classes in that project by adding the following line to my sbt:
unmanagedClasspath in Compile += file("[Path to My Project]/classes")
But this project also has a lib folder with a set of jars that it references and I cannot figure out what the correct syntax should be to add these dependencies. Have tried the following but it does not work:
unmanagedJars in Compile += file("[Path to My Project]/lib/*.jar")
Any pointers greatly appreciated
Regards
Des
You can use sbt's Path API to get all jars in your directory.
Edit: a shorter version using .classpath:
unmanagedJars in Compile ++=
(file("[Path to My Project]/lib/") * "*.jar").classpath
which is more or less equivalent to:
unmanagedJars in Compile ++=
Attributed.blankSeq((file("[Path to My Project]/lib/") * "*.jar").get)
(Attributed is necessary because unmanagedJars is a setting of type Seq[Attributed[File]] and not Seq[File])
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