Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Sbt, idea and eclipse


Published on

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

Published in: Technology
  • Be the first to comment

Sbt, idea and eclipse

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