Setup Scala with SBT in IntelliJ IDEA
Download Dependencies
- Download IntelliJ IDEA Community Edition (10.0.3)
http://www.jetbrains.com/idea/download - Download Scala
http://www.scala-lang.org/downloads (2.8.1 installer) - Download SBT
http://code.google.com/p/simple-build-tool/ (0.7.5)
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
- From sbt prompt run the following (including * character)
- 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
great
ReplyDeleteHi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.
ReplyDeleteyour posting style is very awesome thanx for sharing keep it up........JetBrains PhpStorm Crack 2020.3.3 Keygen Full Download [Win/Mac]
ReplyDeleteAppreciation is a wonderful thing...thanks for sharing kepp it up.Smart Game Booster Crack
ReplyDeleteJetBrains PhpStorm Crack
CDRoller Crack
IDM Crack 6.38 Build 16
WinRAR Crack
IOBIT Uninstaller Pro Key
Great Work Keep it up! PyCharm Crack
ReplyDeleteAppreciation is a wonderful thing...thanks for sharing kepp it up.Windows Movie Maker Crack
ReplyDeleteNative Instruments Massive Crack
Reimage PC Repair Crack
JetBrains PhpStorm Crack
MacBooster Crack
CDRoller Crack