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
ReplyDeleteyour posting style is very awesome thanx for sharing keep it up........JetBrains PhpStorm Crack 2020.3.3 Keygen Full Download [Win/Mac]
ReplyDeleteGreat Work Keep it up! PyCharm Crack
ReplyDeletePyCharm 2020.3.3 Crack
ReplyDeleteI 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.
ReplyDeletehttps://free4crack.net/wp-admin/
JetBrains PhpStorm Crack
keep it up good job JetBrains PhpStorm 2021.1.3 Crack
ReplyDeleteThanks For making post and sharing the important data..keep it up!!!
ReplyDeletePhpStorm 2021.1.3 Crack
Thanks For Post which have lot of knowledge and informataion thanks.... Native Instruments Massive Crack
ReplyDeleteNative Instruments Massive Crack
Native Instruments Kontakt Crack
Native Instruments kontakt Crack
ReplyDeleteI 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