Out of memory error Error while building spark - scala

I am building spark by using sbt. When I run the following command:
sbt/sbt assembly
it takes some time to build spark. There are several warning that appear and at the end I am getting following errors:
[error] java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
[error] Use 'last' for the full log.
When I check sbt version using command sbt sbtVersion, I get following result:
[warn] Multiple resolvers having different access mechanism configured with same name 'sbt-plugin-releases'. To avoid conflict, Remove duplicate project resolvers (`resolvers`) or rename publishing resolver (`publishTo`).
[warn] There may be incompatibilities among your library dependencies.
[warn] Here are some of the libraries that were evicted:
[warn] * com.typesafe.sbt:sbt-git:0.6.1 -> 0.6.2
[warn] * com.typesafe.sbt:sbt-site:0.7.0 -> 0.7.1
.......
[info] streaming-zeromq/*:sbtVersion
[info] 0.13.7
[info] repl/*:sbtVersion
[info] 0.13.7
[info] spark/*:sbtVersion
[info] 0.13.7
When I give command, ./bin/spark-shell, I get following output:
ls: cannot access '/home/neel_shah/spark/spark-1.6.1/assembly/target/scala-2.10': No such file or directory
Failed to find Spark assembly in /home/neel_shah/spark/spark-1.6.1/assembly/target/scala-2.10.
You need to build Spark before running this program.
What can the solution be?

You must configure SBT heap size:
on linux type export SBT_OPTS="-Xmx2G" to set it temporary
on linux you can edit ~/.bash_profile and add line export SBT_OPTS="-Xmx2G"
on windows type set JAVA_OPTS=-Xmx2G to set it temporary
on windows you can edit sbt\conf\sbtconfig.txt and set -Xmx2G
More info:
http://www.scala-sbt.org/0.13.1/docs/Getting-Started/Setup.html
How to set heap size for sbt?

This is probably not a common resolution, but in my case I had to run this command to resolve the OutOfMemoryError when building a spark project with sbt (path is specific to mac OS):
rm -rf /Users/markus.braasch/Library/Caches/Coursier/v1/https/
Increasing memory settings for a variety of arguments in SBT_OPTS did not solve it.

Related

How to correctly prepare and setting preloaded sbt lib

In my situation, I cannot access internet in my office linux server. Therefore, I installed sbt in my personal computer. I followed instructions on sbt official web-site and run/compile a "hello world" for getting all dependency data.
Then, I copied ~/.ivy2 and ~/.sbt and sbt bin folders to my offline office desktop. But when I run sbt, I got these errors:
[info] welcome to sbt 1.4.9 (Oracle Corporation Java 1.8.0_25)
[info] loading project definition from /proj/mtk07847/test/scala/project
[info] Updating
[info] Resolved dependencies
[warn]
[warn] Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading org.scala-lang:scala-library:2.12.12
[error] Not found
[error] Not found
[error] download error: Caught java.net.SocketException: Connection reset (Connection reset) while downloading https://repo1.maven.org/maven2/org/s
cala-lang/scala-library/2.12.12/scala-library-2.12.12.pom
[error] not found: ~/.ivy2/localorg.scala-lang/scala-library/2.12.12/ivys/ivy.xml
...
It seems that sbt tried to download missing scala-library:2.12.12 which I already prepared.
In my ~/.ivy2 folder,the structure and path looks like the following:
~/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.12.12.jar
~/.ivy2/cache/org.scala-lang/scala-library/ivy-2.12.12.xml
~/.ivy2/cache/org.scala-lang/scala-library/ivy-2.12.12.xml.original
~/.ivy2/cache/org.scala-lang/scala-library/ivydata-2.12.12.properties
which is different from above messages:
[error] not found: ~/.ivy2/localorg.scala-lang/scala-library/2.12.12/ivys/ivy.xml
should I modified any describing files to indicate searching path or rule for sbt? or this method
is totally wrong (if so, can anyone know the flow guide me the better way?)

failed to create .ensime file, how can I do?

I have been trying to use ensime with sublime to use Scala. To install ensime I created a plugin.sbt in this location
~/.sbt/1.0/plugins/plugins.sbt
here is the screen shot
I also added "addSbtPlugin("org.ensime" % "sbt-ensime" % "2.0.1")" in the plugin.sbt. But when I run sbt and run the command "ensimeConfig" to create .ensime file I get error
C:\Users\Mahadi>sbt
"C:\Users\Mahadi\.sbt\preloaded\org.scala-sbt\sbt\"1.0.1"\jars\sbt.jar"
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; sup
port was removed in 8.0
[info] Loading global plugins from C:\Users\Mahadi\.sbt\1.0\plugins\project
[info] Loading settings from plugins.sbt ...
[info] Loading global plugins from C:\Users\Mahadi\.sbt\1.0\plugins
[info] Loading project definition from C:\Users\Mahadi\project
[info] Set current project to mahadi (in build file:/C:/Users/Mahadi/)
[info] sbt server started at 127.0.0.1:5547
sbt:mahadi> ensimeConfig
[error] Not a valid command: ensimeConfig
[error] Not a valid project ID: ensimeConfig
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: ensimeConfig
[error] ensimeConfig
[error] ^
sbt:mahadi>
So I am looking for your help.
Youn should run sbt in the root directory of your sbt project, as the ensime configuration file is built based on it.

Why is Typesafe activator command `activator dependencies` not working?

I created a new project using Typesafe Activator. In the command prompt I execute the command activator dependencies. This results in:
E:\sample_app>activator dependencies
[info] Loading project definition from E:\sample_app\project
[info] Updating {file:/E:/sample_app/project/}sample_app-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to sample_app (in build file:/E:/sample_app/)
[error] Not a valid command: dependencies
[error] Not a valid project ID: dependencies
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: dependencies (similar: all-dependencies, rpm-dependencies, allDependencies)
[error] dependencies
[error] ^
Versions used:
Java version is 1.8.0_51,
Activator is 1.3.6,
OS is windows 8,
64 - bit OS.
Analysis
First, dependencies is not valid sbt commands. (All sbt commands can be used also in activator.)
Solution
Either you mean libraryDependencies (which is an sbt setting) so call
activator libraryDependencies
Or you want to see the classpath of the dependencies ( a sbt task, so you need to use show to see the output of the sbt task), e.g.
activator "show dependencyClasspath"
Edit as of 2015-09-30,3:50am
If calling from console, the combined command must be put into quotes. Here: "show dependencyClasspath"

How to download sbt plugin source jars in a common sbt project?

It's nature to download the dependencies source jars in a sbt project, using sbt gen-idea or idea's autoimport feature
but how can I download the sbt plugin source jars which I declared in project/plugins.sbt
IDEA
IDEA should already do this*.
When you import a project and have Download sbt sources checked in Preferences > Build, Execution, Deployment > Build Tools > sbt then it will run the updateSbtClassifiers sbt task.
* Read the Troubleshooting section as there are several known issues with this.
sbt
As mentioned above, you can run the following sbt task:
sbt> updateSbtClassifiers
This command is somewhat special in that it knows to resolve the classifiers for the plugins. It also uses settings that are scoped to that task. See the caveat about sbt/sbt#3432.
Longer way
It is important to understand that sbt is recursive.
Dependencies declared in build.sbt will be for the proper build.
Dependencies declared in project/plugins.sbt will be for the meta-build.
When you just run updateSbtClassifiers it is running this on the proper build, however the dependencies are actually for the meta-build. That is why I said that this task is a little special.
Another way (which can achieve different results) is to run the updateClassifiers task directly on the meta-build.
First switch over to the meta-build:
sbt> reload plugins
Now that you are in the meta-build run:
sbt:project> updateClassifiers
This will retrieve the src and doc for your dependencies (it may not actually do this for some plugins). Run libraryDependencies to see the dependencies of the meta-build.
To get back to the proper
sbt:project> reload return build run:
Troubleshooting
Download failed
You may see in the sbt logs that it failed to download either the src or doc. For example:
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: FAILED DOWNLOADS ::
[warn] :: ^ see resolution messages for details ^ ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: rocks.muki#sbt-graphql;0.5.0!sbt-graphql.jar(doc)
[warn] :: rocks.muki#sbt-graphql;0.5.0!sbt-graphql.jar(src)
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
If you look just above you will see all the resolvers that it tried. You should see one for sbt-plugin-releases which is where most sbt plugins are published to. See predefined resolvers for more details.
If you do not see that it tried sbt-plugin-releases then chances are you have encountered sbt/sbt#3432.
updateSbtClassifiers does not use the correct resolvers. Add the following to your build.sbt file:
updateSbtClassifiers / dependencyResolution := IvyDependencyResolution((updateSbtClassifiers / ivyConfiguration).value)
Sources not attaching
Even if the updateSbtClassifiers successfully downloads and resolves the src and doc IDEA may not attach them.
This seems to be a bug in the sbt-structure plugin. See SCL-13619 for details.
No attempt at downloading
If for some reason this doesn't download the sources (there is no failed download message) then have a look in your .ivy2/exclude_classifiers file. I'm not entirely sure what this file is for but I do know that sbt will exclude anything that is in here.
In my case it had a whole lot of things that I didn't want excluded so I deleted it and then it worked. Delete at your own risk.
You can use reload plugins to go into the project that contains the plugins. If you type libraryDependencies you can (for example) see the list of plugin dependencies. Use reload return to return to your normal sbt console.
More information here: Commands for managing the build definition

"./sbt/sbt assembly" errors "Not a valid command: assembly" for Apache Spark project

I'm having trouble with installing Apache Spark on Ubuntu 13.04. Im using spark-0.8.1-incubating, and both ./sbt/sbt update and ./sbt/sbt compile work fine. However, when I do a ./sbt/sbt assembly I get the following error:
[info] Set current project to default-289e76 (in build file:/node-insights/server/lib/spark-0.8.1-incubating/sbt/)
[error] Not a valid command: assembly
[error] Not a valid project ID: assembly
[error] Not a valid configuration: assembly
[error] Not a valid key: assembly
[error] assembly
[error]
I googled for stuff related to this but couldn't find anything useful. Any guidance would be much appreciated.
The current project set to default-289e76 message suggests that sbt was called from outside of the Spark sources directory:
$ /tmp ./spark-0.8.1-incubating/sbt/sbt assembly
[info] Loading global plugins from /Users/joshrosen/.dotfiles/.sbt/plugins/project
[info] Loading global plugins from /Users/joshrosen/.dotfiles/.sbt/plugins
[info] Set current project to default-d0f036 (in build file:/private/tmp/)
[error] Not a valid command: assembly
[error] Not a valid project ID: assembly
[error] Not a valid configuration: assembly
[error] Not a valid key: assembly
[error] assembly
[error] ^
Running ./sbt/sbt assembly works fine from the spark-0.8.1-incubating directory (note the log output showing that the current project was set correctly):
$ spark-0.8.1-incubating sbt/sbt assembly
[info] Loading global plugins from /Users/joshrosen/.dotfiles/.sbt/plugins/project
[info] Loading global plugins from /Users/joshrosen/.dotfiles/.sbt/plugins
[info] Loading project definition from /private/tmp/spark-0.8.1-incubating/project/project
[info] Loading project definition from /private/tmp/spark-0.8.1-incubating/project
[info] Set current project to root (in build file:/private/tmp/spark-0.8.1-incubating/)
...
You typed "abt" twice, but shouldn't that be "sbt"? Apache Spark has its own copy of sbt, so make sure you're running Spark's version to pick up the "assembly" plugin among other customizations.
To run the Spark installation of sbt, go to the Spark directory and run ./sbt/sbt assembly .