SBT increase compilation memory - scala

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

Related

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.

Intellij doesn't seem actually run `sbt update` for modified dependencies

I recently updated a personal scala library that I have published to my local maven repo. In another project which uses this library, intellij refuses to acknowledge that this new library exists. In fact, it seems to be disregarding the contents of the build.sbt file altogether. Below is my current build.sbt file, with the updated dependency package (org.mechko.data).
name := "algorithms"
organization := "org.mechko"
version := "1.0"
scalaVersion := "2.10.4"
publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository")))
resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
libraryDependencies += "org.mechko" % "data_2.10" % "1.0.1" //updated dependency
It seems that running sbt update and sbt run in the terminal delivers the desired result using my updated library, so the problem is entirely with intellij. I have tried restarting intellij, and also invalidating the cache. I even tried putting incoherent garbage in my sbt file. Nothing evokes a response when I click refresh project. Any idea what might be the issue?
Thanks
My ultimate solution had three parts:
Uninstall and reinstall the scala plugin for intellij
Run sbt clean from the terminal
Delete the .idea folder in the project root and reimport the project
I tried combinations of these steps, but only when I did all three did Intellij agree to actually run the updates.

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.

Running SBT with -deprecation

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.

How do I force SBT plugins and plugins to be downloaded through Nexus?

I think that by now I figured out how to force project dependencies to be downloaded through Nexus. (I did that by explicitly setting externalResolvers to a Seq with only one value:
override lazy val settings = super.settings ++ Seq(
externalResolvers := Seq("Nexus repository" at "http://.../nexus/content/groups/public/")
)
However, if I drop my Ivy cache, SBT still accesses a number of public repositories for getting the plugins. Ideally I would like that to go through Nexus as well, to make sure we are not dependent on those repositories to exist forever. (Which they don't.)
Any clues? (I'm on SBT 0.11.2)
sbt 0.12 added Global repository setting for this purpose.
Define the repositories to use by putting a standalone [repositories] section (see the Launcher Specification page) in ~/.sbt/repositories and pass -Dsbt.override.build.repos=true to sbt. Only the repositories in that file will be used by the launcher for retrieving sbt and Scala and by sbt when retrieving project dependencies.