How to import SBT dependencies manually in intellij - scala

I want to use Intellij as Spark and Scala editor so I should create an SBT project. Scala and SBT plugins are installed, but the problem is when I create SBT project, at the first it try to fetch SBT plugins and dependencies from here but it stuck on sbt getting org.scala-sbt 0.13.13 step! sometime it progresses but finally errors time out! I have access to address SBT want get dependencies by browser and I want to know is it possible to download dependencies manually and put in the right place ?

You can find the detailed steps in this chapter of Scala Cookbook. In build.sbt file you should add a resolver key including the Ivy repository you want.
resolvers += "Your Repository" at "Repository Location"

Related

sbt gen-idea fails : trying to import a sbt-managed project TopNotch from github

I have done git clone on the TopNotch project from github and wanted to import this sbt project to Intellij.
I am under the root directory of TopNotch and have sbt gen-idea, it failed with "Not a valid command"
Link to TopNotch: https://github.com/blackrock/TopNotch
So, I have added the below lines under project/plugins.sbt but still fails with
"bt.ResolveException: unresolved dependency: com.github.mpeltonen#sbt-idea;1.7.0-SNAPSHOT: not found"
Lines added:(also tried with 1.5.0-SNAPSHOT"
resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
addSbtPlugin(dependency="com.github.mpeltonen" % "sbt-idea" % "1.7.0-SNAPSHOT")
I have SBT-0.13.11 installed but the build has 0.13.8
Scala - 2.11.8
Java 1.8
Intellij - 2016.1.3
Please suggest how to import the project.
Thank you.
sbt-idea plugin had been unsupported since it was included into official Scala plugin about two years ago, and project files generated by outdated version of the plugin are not compatible with IntelliJ IDEA starting with version 14, if I recall correctly.
The common approach is to install Scala plugin from IDEA (Settings > Plugins > Install JetBrains Plugin > search for Scala) and import your SBT project using the standard Open... dialog afterwards.

How to create executable jar in scala which can run on jvm?

I am using scala version 2.11.4, I have tried various options like sbt-assembly, build artifact (Intellij Idea feature), sbt package. Unfortunately, none of them worked form me.
I attempted following things :
With sbt-assembly :
Created assembly.sbt file and added following line :
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.12.0")
build.sbt :
scalaVersion in ThisBuild := "2.11.4"
resolvers += Resolver.url("bintray-sbt-plugins", url("http://dl.bintray.com/sbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns)
ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }
I got the following error
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] com.eed3si9n:sbt-assembly:0.12.0 (sbtVersion=0.13, scalaVersion=2.11)
With 'build artifact' feature using Intellij Idea 15
Able to create a jar. However, not able to execute it. Was getting following error:
Invalid or corrupt jarfile
For this I tried the command : java -jar JAR_FILE
With sbt package :
Able to create JAR. However, not able to execute it. Was getting following error :
java.lang.NoClassDefFoundError scala/Function0
I was trying with the command :
java -cp scala-library.jar -jar JAR_FILE
Resolved
I am able to create jar by switching to scala version 2.10.5 and then used sbt-assembly plugin. Slightly disappointed with the fact that there is no available solution to create executable jar with latest version of scala.
If you are using sbt-assembly plugin, the correct task to perform is called assembly. When using IntelliJ IDEA, sbt assembly needs to be performed from a command line, the IDE is still unable to perform such SBT tasks.
The resulting jar, which includes all dependencies, is usually called a fat jar - if you need some more searching, this is what to search for.
Since I can't comment yet, I'll use answer, but more of a question - I have been using sbt package extensively for exactly this. I cd into the directory that holds src/main/scala|java and running sbt package, and then pushing jar/war file to the desired destination, in my case jetty.
Can you explain exactly what you're doing, the output and details on the issue?

sbt is using wrong scala version rather than using the configuration in build.sbt

I have put these in the build.sbt file under current project's root directory
scalaHome := Some(file("/Users/ddam/scala-2.10.2"))
scalaVersion := "2.10.2"
And I ran sbt using
$ sbt --version
sbt launcher version 0.12.4
But still, I am seeing both the wrong version for sbt and scala when a particular dependency cannot be resolved
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] com.typesafe.sbteclipse:sbteclipse-plugin:2.4.0 (sbtVersion=0.12, scalaVersion=2.9.2)
Please help me.
It looks like sbteclipse requires SBT 0.13.0, and you are using version 0.12.4.
You can specify the SBT version by following the directions on this page.
Some other notes: You probably want to use Scala 2.10.3, not 2.10.2.
Also, it's strange to specify scalaHome; usually SBT will automatically fetch the needed Scala jars for you.
So to bootstrap a Scala environment, all you need to have installed are SBT and a JDK.
EDIT: (addressing comment below):
When you build code with SBT, you may actually use two different versions of Scala.
There is the version for SBT (what version of Scala the build system runs on), and the version for the code in your project (what version of Scala your code will run on).
The Scala version for SBT is determined by the SBT version you use.
If you use 0.12.4, SBT will run on Scala 2.9.3.
If you use 0.13.0, SBT will run on Scala 2.10.3.
You control the SBT version by following these instructions.
To control the version of Scala your project will run on, you can set scalaVersion in <projectRoot>/build.sbt.
So, you're getting that error because you're using SBT 0.12.4, which uses Scala 2.9.3.
SBT tries to find the sbteclipse plugin for 2.9.3, but it doesn't exist because it requires SBT 0.13.0 (=> Scala 2.10.3).
It seems you've correctly specified the use of Scala 2.10.2 for compiling your project.
sbt 0.12.4 always uses Scala 2.9.x to compile the build files (i.e. build.sbt and the stuff under project/). This means that plugins for sbt 0.12.x must also be compiled against 2.9.x, which explains what you're seeing.
sbteclipse 2.4.0 requires sbt 0.13. Try sbteclipse 2.2.0 if you want to stay on sbt 0.12.4.
emchristiansen's answer has good additional points.

sbt version and scala version. project configuration for intellij idea with sbt-idea plugin

I follow these steps to configure a project for IntelliJ idea.
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0")
I use sbt-idea for sbt version 0.12 with fixed bug for Idea.
When I type sbt in my project's directory, I noticed that it uses scala 2.9.2.. but I'm going to use scala 2.10.1 for my project.
Questions:
Does it make sense which scala version to use for plugin(s) (~/.sbt/plugins)-compilation, or I should use one/same scala version for everything? Can I change scala version for plugins?
So, I created ~/.sbt/plugin/build.sbt file with mentioned content.
that version is out of date, it depends on sbt-idea 1.2.0-SNAPSHOT. The latest at the time of writing is 1.3.0
See my project skeleton for an implementation using the latest versions of scala, scalatest and SBT to IDE project plugins.
Actually I got it.
if you have a project with build.sbt (that uses 2.10.1 scala) file - as soon as you type sbt.. all dependencies will be downloaded into ~/.sbt folder - even scala compiler will be downloaded there (~/.sbt/boot). It could be even several version of scala: 2.10.1 and 2.9.2 for example.
and about sbt-idea and ~/sbt/plugins .. it could any scala version - depending on its build.sbt file, for example in my case:
resolvers += "Sonatype snapshots" at
"http://oss.sonatype.org/content/repositories/snapshots/"
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0-SNAPSHOT")
I should notice if try different version.. like 1.1.0-M2-TYPESAFE it will not work.. (at least in my case) - gen-idea command is not available then. I do not know why. I guess it should.
Also if you do not point resolvers += - it will will not work.. but it it will not tell you about that..
This plugin is using scala 2.9.2 - we can not see it here, but we can see it from that outputs it produces while installing/downloading. That's why we have ~/.sbt/boot/scala-2.9.2/ as a result.
In any case we should not care about it. It is handled by sbt.
When you converted your sbt-project into your intellij-idea project by typing gen-idea in sbt console, as the result your IDE project will be referencing to ~/.sbt/scala but not to your somewhere-installed-scala.. So even no need to pointing the scala location - that sbt-idea sbt's plugin will do all the work. And that's good!
That's the answer I wanted to get. One gets/understands it by trying it.

setting sbt scalafx project

javafx is now in oracle-jdk.
scalafx gives delicious examples in its repository
The main questions I'm not being able to answer is "How to get started with scalafx"?
How can I add scalafx libary dependencies on my sbt project?
ScalaFX is soon to reach a stable release state.
As I write this you can find the published artifacts for version 1.0.0-M2 on the maven central repo
Adding the dependency to your sbt build should suffice
libraryDependencies += "org.scalafx" %% "scalafx" % "1.0.0-M2"
I did it the following way: I cloned the scalafx repository, build the jar using sbt package, then just copied the resulting jar into lib/ directory of my project. Make sure to reference your ${JAVAFX_HOME}/lib/jfxrt.jar as well.
If you want to use local maven, just run sbt publish-local in your scalafx dir, then add the following dependency to your project:
"org.scalafx" % "scalafx" % "1.0-SNAPSHOT"
(Look up that version in scalafx build.sbt, I pasted what was in mine)
#ayvango i have created a giter8 scalafx project template.just use
g8 jugchennai/scalafx.g8
You just need a new version of JDK, Giter8 and SBT. Dependency settings for javafx, scala, scalafx are predefined! IDE support also available.
URL : https://github.com/jugchennai/scalafx.g8