• Save
Sbt, idea and eclipse
Upcoming SlideShare
Loading in...5
×
 

Sbt, idea and eclipse

on

  • 1,910 views

The author is managing editor of http://scalacourses.com, which offers self-paced online courses that teach Introductory and Intermediate Scala and Play Framework.

The author is managing editor of http://scalacourses.com, which offers self-paced online courses that teach Introductory and Intermediate Scala and Play Framework.

Statistics

Views

Total Views
1,910
Views on SlideShare
1,907
Embed Views
3

Actions

Likes
3
Downloads
0
Comments
0

3 Embeds 3

http://a0.twimg.com 1
http://twitter.com 1
http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Sbt, idea and eclipse Sbt, idea and eclipse Presentation Transcript

  • Mike Slinn SF Scala Meetup Nov 21, 2011 sbt, IDEA and Eclipse
  • Simple Build Tool (sbt)
      • Generates Maven-compatible projects
      • Uses DSL instead of XML to define projects
      • pre-v0.10: class/inheritance based build system
      • v0.10: introduced functional build system
      • v0.11.1 is current (get the update!)
      • Scala code can be interspersed with DSL
      • Most examples on the interwebs are for older versions of sbt and are more complex than necessary
  • Two types of build.sbt
    • Project dependencies and settings
      • $PRJ_HOME/build.sbt
    • Toolchain enhancements
      • Project specific: $PRJ_HOME/project/build.sbt
      • Global: ~/.sbt/plugins/build.sbt
      • Windows & cygwin users: put global build.sbt in %home%
    • The above are quick and easy to set up
    • More files possible in the toolchain directories; water gets deep fast
  • Sample project build.sbt
    • import com.typesafe.startscript.StartScriptPlugin seq(StartScriptPlugin.startScriptForClassesSettings: _*) name := "hanuman" version := "0.1" scalaVersion := "2.9.1" scalacOptions ++= Seq("-deprecation") resolvers ++= Seq(  "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases",  "Sonatype"          at "http://nexus.scala-tools.org/content/repositories/public",  "Scala Tools"       at "http://scala-tools.org/repo-releases/",  "JBoss"             at "http://repository.jboss.org/nexus/content/groups/public/",  "GuiceyFruit"       at "http://guiceyfruit.googlecode.com/svn/repo/releases/" ) libraryDependencies ++= Seq(  "se.scalablesolutions.akka" % "akka-actor"       % "latest.integration"              withSources(),  "se.scalablesolutions.akka" % "akka-stm"         % "latest.integration"              withSources(),  "se.scalablesolutions.akka" % "akka-typed-actor" % "latest.integration"              withSources(),  "com.reportgrid"           %% "blueeyes"         % "latest.integration"  % "compile" withSources(),  "org.scalatest"            %% "scalatest"        % "latest.integration"  % "test"    withSources() )
  • About build.sbt
      • Blank line between statements required
      • Compound statements are single spaced
      • Most important sections are resolvers and libraryDependencies
  • build.sbt resolvers
      • Defines where to find dependencies
      • resolvers ++= Seq(
      • "Typesafe Releases" at
      • "http://repo.typesafe.com/typesafe/releases",
      • "Sonatype" at
      • "http://nexus.scala-tools.org/content/repositories/public",
      • "Scala Tools" at
      • "http://scala-tools.org/repo-releases/",
      • "JBoss" at
      • "http://repository.jboss.org/nexus/content/groups/public/",
      • "GuiceyFruit" at
      • "http://guiceyfruit.googlecode.com/svn/repo/releases/"
      • )
  • build.sbt libraryDependencies
      • libraryDependencies ++= Seq(
      • "se.scalablesolutions.akka" % "akka-actor" % "latest.integration" withSources(),
      • "se.scalablesolutions.akka" % "akka-stm" % "latest.integration" withSources(),
      • "se.scalablesolutions.akka" % "akka-typed-actor" % "latest.integration" withSources(),
      • "com.reportgrid" %% "blueeyes" % "latest.integration" % "compile" withSources(),
      • "org.scalatest" %% "scalatest" % "latest.integration" % "test" withSources()
      • )
      • Note that the ScalaTest dependency is only provided for testing
      • IDEA automatically applies withSources() and withJavadoc()
      • %% "blueeyes" expands to "blueeyes_2.9.1"
      • " latest.integration " is helpful for development, may not be good for production
  • Useful sbt Plugins
      • sbt-idea - creates IDEA 10 project from sbt. Works really well
      • sbteclipse - creates Eclipse project from sbt.
        • v1.3 (current) writes to .target instead of target
        • Must edit .classpath file to correct
      • sbt-assembly - builds a single JAR file of a project which includes all of its dependencies
  • Sample Global build.sbt
      • resolvers += "sbt-idea-repo" at http://mpeltonen.github.com/maven/
      • resolvers += Classpaths.typesafeResolver
      • addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "0.11.0")
      • addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse" % "1.4.0")
      • addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.2")
  • Useful sbt Commands
      • help command* - Displays help message or prints detailed help on requested commands.
      • show - run a task and print the resulting value (not required for all tasks, like compile )
      • $ sbt 'show homepage'
      • tasks - Displays the tasks defined for the current project.
  • Common sbt Tasks (1)
      • assembly-package-dependency - for sbt-assemply
      • clean - Deletes files produced by the build, such as generated sources, compiled classes, and task caches.
      • compile - Compiles sources.
      • ~compile - Continuously compiles sources.
      • console - Starts the Scala interpreter with the project classes on the classpath.
  • Common sbt Tasks (2)
      • console-project - Starts the Scala interpreter with the sbt and the build definition on the classpath and useful imports.
      • container:start - Starts Jetty (if defined for project)
      • copy-resources - Copies resources to the output directory ( target/scala-2.9.1/classes/)
      • credentials - For updating and publishing.
  • Common sbt Tasks (3)
      • doc - Generates Scaladoc ( target/scala-2.9.1/api/ )
      • full-classpath - The exported classpath, consisting of build products and unmanaged and managed, internal and external dependencies.
      • offline - Configures sbt to work without a network connection where possible.
      • package - Produces the main artifact, such as a binary jar. (e.g. target/scala-2.9.1/hanuman_2.9.1-0.1.jar )
  • Common sbt Tasks (4)
      • publish - Publishes artifacts to a repository.
      • run - Runs a main class, passing along arguments provided on the command line.
      • test - Executes all tests.
  • IDEA 10.5 and Scala
      • Scala and sbt plugins not offered during installation, must be enabled afterwards
      • Excellent integration with sbt
      • Excellent run/debug capability
      • Mediocre type-aware highlighting
      • Weak syntax checking, especially with DSLs
      • Weak debugging - often cannot display variables
      • Poor Scala intellisense
  • sbt Project Structure shown in IDEA
  • sbt Project Dependencies Shown in IDEA
  • IDEA deploy dependencies before run
  • Eclipse and Scala v2 Plugin
      • Eclipse Scala plugin not as good as IDEA Scala plugin
      • No sbt support
      • Needs more memory than IDEA + Scala
      • Poor type-aware highlighting
      • Often wrong syntax checking, especially with DSLs
      • Weak debugging - often cannot display variables
      • Poor Scala intellisense
      • Does not handle user types
  • Thank you!