Setup Scala with SBT in IntelliJ IDEA

Download Dependencies

Setup 

  • Setup SBT according to this page (Launching Sbt section)
    http://code.google.com/p/simple-build-tool/wiki/Setup
  • Add Scala/SBT plugins to IntelliJ IDEA
    • Go to File/Settings/Plugins, choose Available tab, right click on Scala plugin and click on 'Download and Install'. Do the same for SBT plugin.
    • Restart IntelliJ IDEA
    • Go to File/Settings/SBT and set location of your SBT jar file and if you're on windows behind firewall add proxy info to vm params (-Dhttp.proxyHost=<proxy_server> -Dhttp.proxyPort=<proxy_port>)

Create Project

  • Create new Folder ScalaProject
  • Run sbt command from that folder, choose 'y' to create new project (Name: ScalaProject, Organization: test) 
  • Configure sbt-idea plugin (https://github.com/mpeltonen/sbt-idea) - you only need to do it once
    • From sbt prompt run the following (including * character)
        > *sbtIdeaRepo at http://mpeltonen.github.com/maven/
        > *idea is com.github.mpeltonen sbt-idea-processor 0.4.0
        > update
  • Create idea project files
      > idea
  • Open the project in IntelliJ IDEA
  • Configure scala plugin file for sbt-idea
    • Create directory ScalaProject/project/plugins
    • Create new file Plugins.scala in ScalaProject/project/plugins folder 
import sbt._ 
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
  val sbtIdeaRepo = "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"
  val sbtIdea = "com.github.mpeltonen" % "sbt-idea-plugin" % "0.2.0"
}  
  • Configure sbt project definition file
    • Create directory ScalaProject/project/build
    • Create scala class file ScalaProject in ScalaProject/project/build folder
import sbt._ 
class ScalaProject(info: ProjectInfo) extends DefaultProject(info) with IdeaProject {
  val scalatest = "org.scalatest" % "scalatest" % "1.3"
}      
  • Refresh project files   
    • Launch SBT Console (bottom of the screen) and press Run (green arrow) 
    • From SBT prompt run the following
      > update
      > clean
      > compile
      > idea   
    • Reload the project

Hello World example

  • Create new scala class HelloWorld in src/main/scala
object HelloWorld {
  def main(args: Array[String]){
    println(hello)
  } 
  def hello:String = {
    return "Hello World!";
  }
}  
  • Create new scala test class HelloWorldSpec in src/test/scala
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
class HelloWorldSpec extends FlatSpec with ShouldMatchers {
  "Hellow World" should "show Hello World" in {
    HelloWorld.hello should equal("Hello World!")
  }
}      

Testing Hello World example

  • Launch SBT Console to run the examples
  • From SBT prompt run the following
    > run (searches for classes with main(args) method and executes them)
    > test (searches for test classes and execute them)
    > ~test (runs tests continuously as soon as it detects changes), press ENTER to exit

Enjoy Scala!

This seems like a good tutorial for beginners
http://www.scala-lang.org/docu/files/ScalaTutorial.pdf

Comments

  1. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues.
    https://free4crack.net/wp-admin/
    JetBrains PhpStorm Crack

    ReplyDelete
  2. keep it up good job JetBrains PhpStorm 2021.1.3 Crack

    ReplyDelete
  3. Thanks For making post and sharing the important data..keep it up!!!
    PhpStorm 2021.1.3 Crack

    ReplyDelete
  4. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to Download All Crack Software's For Free Here But thankfully, I recently visited a website named Crackroom
    8 Ball Pool Crack
    Tekken 7 Ultimate Edition Crack
    Autodesk AutoCAD Crack
    PhpStorm Crack
    Cubase Full Pro Crack

    ReplyDelete

  5. I am very happy to read this article. Thanks for giving us Amazing info. Fantastic post.
    Thanks For Sharing such an informative article, Im taking your feed also, Thanks.macbooster crack

    ReplyDelete

Post a Comment

Popular posts from this blog

Parse XML to dynamic object in C#

C# Updating GUI from different thread