Running SBT with -deprecation - scala

I seem to have warnings in my project/build.scala file (NOT IN MY SCALA PROJECT). How do I configure SBT to run with the -deprecation flag.
// Does not help so do not suggest it!
scalacOptions ++= Seq("-unchecked", "-deprecation")
I know that SBT has the sbt.boot.properties files, but can't figure out if the flag should go in there or not. And if it is an example would be nice. Thx in advance.
BTW
I use SBT launcher for 0.12.2 and have the issue both with SBT 0.12.2 and 0.11.3. And I'm on Ubuntu in case that matters.

Simply put the scalacOptions setting in project/build.sbt. Settings for your project and your build definition go in different files, because they have to be compiled before they can be used and as you want to change compiler settings, this is not possible to handle in the same file.
edit: Just to prevent confusion, ./build.sbt, project/build.scala and project/build.sbt are different. In the first one you put your normal settings for the project and in the latter two (never both used together) you can put settings that affect the compilation of your project files.

Related

Sbt Plugins vs Compiler Plugins

I am trying to understand why Adding sbt plugins in plugins.sbt in the project, works perfectly fine, but if I add the compiler plugins in that file it does not work ?
I thought any .sbt or .scala file in project, is made available for the build definition.
The only place where compiler plugins works is in the build.sbt. Hence i am confused as to why ?
In particular i am working with Kind-Projector
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.11.3" cross CrossVersion.full)
I see the following alias for the function
/** Adds `dependency` to `libraryDependencies` in the auto-compiler plugin configuration. */
def addCompilerPlugin(dependency: ModuleID): Setting[Seq[ModuleID]] =
libraryDependencies += compilerPlugin(dependency)
Hence just trying to understanding, what makes it that it can only be added to the build.sbt and not plugins.sbt in project/
Remeber sbt is recursive.
.sbt define things that are available in the current layer.
.scala files define thins that will be available in the next layer.
Adding an sbt plugin in project/bar.sbt is adding that plugin to the meta layer, as such the meta-layer that compiles the sbt you are using to compile your project adds those plugins to the next sbt layer.
So if you add a compiler plugin in project/foo.sbt then you are adding that compiler plugin to the compiler used to compile the project (meta) layer of sbt, but it will not be available in the current layer of sbt. That is the reason why compiler plugins are added in the build.sbt file, so they are added to the compiler used to compile your code.

SBT increase compilation memory

How can I increase the compilation memory for the project in the build.sbt? Not in the general SBT config.
I want the config to be committed into my Git repo.
Cheers
Create .sbtopts file in root of your SBT project and put in -J-Xmx4G (and similarly -J<JVM option>. Unfortunately, it doesn't seem to work on Windows.
the apparent solution would be to do it this way:
scalacOptions in ThisBuild ++= Seq ("-JXss512m","-JXmx2G")
while I see these values display when I run:
sbt
show scalacOptions
the settings do not seem to be honored by the actual compiler

Intellij sbt sbt-native-packager and enablePlugins error

I have an sbt build that works when I run from the command line, but that Intellij does not like. My Intellij is running on Linux, its version is 14.1.4, my scala plugin is 1.5.2.
Intellij complains about my use of enablePlugins(JavaAppPackaging). The error is "Expression Type (DslEntry) must conform to Setting[_] in SBT file".
My project/build.properties file:
sbt.version=0.13.8
My project/plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.3")
And the first few lines of my build.sbt
enablePlugins(JavaAppPackaging)
organization := "org.bodhi"
name := "jar-patch"
version := "1.0"
The answer by #lifeGoGoGo on another thread Intellij IDEA and SBT syntax error works for me (on Ubuntu, setting the custom sbt-launcher.jar in global settings and project settings of IntelliJ IDEA - as sensibly answered by #Mustafa on this thread - wasn't enough, but then adding the "lazy val" tactic was enough). So for example, this worked for me in build.sbt (obviously you change your plugin-details to suit what you are doing, as this issue is caused by IntelliJ and not by the specific plugin you want to enable):
lazy val root = (project in file(".")).
enablePlugins(ScalaJSPlugin).
settings(
name := "Scala.js Tutorial",
scalaVersion := "2.11.7",
version := "1.0"
)
IntelliJ uses a bundled SBT launcher which might be a different version than what you are running in the command line.
Since you already know that command line SBT works, you may point IntelliJ to use the command line SBT instead of the bundled one.
Go to settings page for SBT at Settings -> Build, Execution, Deployment -> Build Tools -> SBT.
In the launcher section, choose Custom and point to the SBT launcher installed in the OS. In Ubuntu, the default location is /usr/share/sbt-launcher-packaging/bin/sbt-launcher.jar
#karol: I had the same problem. I solved by choosing again at the moment of opening the project /usr/share/sbt-launcher-packaging/bin/sbt-launcher.jar in
"Import Project from SBT" -> Global SBT settings.
The issue is due to how IntelliJ IDEA marks syntax errors, which may mark valid code red. This particular error will be fixed soon.

How to use external dependencies in sbt's .scala files?

This is for Scala 2.11.1 and sbt 0.13.5.
Say I have a Scala/sbt project with the following directory structure:
root/
build.sbt
src/ ..
project/
plugins.sbt
build.properties
LolUtils.scala
and I want to use some external library in LolUtils.scala. How is this generally accomplished in sbt?
If I simply add the libs I need into build.sbt via libraryDependencies += .. then it doesn't find them and fails on the import line with not found: object ...
If I add a separate project/build.sbt, for some reason it starts failing to resolve my plugins, plus I need to manually specify the Scala version in the nested project/build.sbt, which is unnecessary duplication.
What's the best way to accomplish this?
sbt is recursive which means that it uses itself to compile a build definition, i.e. *.sbt files and *.scala files under project directory. To add extra dependencies to use them in the build definition you have to declare them in a project/build.sbt.
There is one caveat to that. You can set any scalaVersion to your project, that is in build.sbt, but you should not modify scalaVersion in the project/build.sbt as it might conflict with the version sbt itself uses (that may or may not lead to binary incompatibility for plugins).
Sbt 0.13.5 is using Scala 2.10.4, and the library you're going to use must be compatible with that particular version of Scala.
> about
[info] This is sbt 0.13.5
...
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4

IntelliJ 13 with SBT plugin does not recognize Scalding dependency

I am trying to add Scalding 2.10 as a managed dependency via build.sbt like so:
name := "ss"
version := "1.0"
libraryDependencies += "com.twitter" % "scalding_2.10" % "0.10.0"
IntelliJ downloads the jar and adds it as an external library (see screen below) but fails to resolve the com.twitter namespace.
I have tried both invalidating the IntelliJ cache and generating project files via sbt gen-idea but neither solutions have worked. Any ideas would be greatly appreciated.
The scalding jar file scalding_2.10 has no code in it to compile against. Its just 300 Bytes in size.
The correct dependency I feel should be
libraryDependencies += "com.twitter" % "scalding-core_2.10" % "0.11.1"
As the comment suggest try rm-ing your ivy2 cache, and try sbt gen-idea. If that doesn't work, other things to check:
makes sure you have indeed got the scala plugin installed.
Most likely you're java SDK is not set or pointing somewhere wrong; right click the project dir, click "Open Module Settings", go to SDK and make sure the path is correctly set to the jdk otherwise syntax highlighting will likely break.
To test your deps have been properly pulled in from tinternet, try sbt compile; if it compiles then you should indeed have downloaded the dependency properly.