Sbt, idea and eclipse

  • 1,469 views
Uploaded on

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.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,469
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Mike Slinn SF Scala Meetup Nov 21, 2011 sbt, IDEA and Eclipse
  • 2. 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
  • 3. 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
  • 4. 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() )
  • 5. About build.sbt
      • Blank line between statements required
      • Compound statements are single spaced
      • Most important sections are resolvers and libraryDependencies
  • 6. 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/"
      • )
  • 7. 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
  • 8. 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
  • 9. 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")
  • 10. 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.
  • 11. 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.
  • 12. 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.
  • 13. 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 )
  • 14. 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.
  • 15. 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
  • 16. sbt Project Structure shown in IDEA
  • 17. sbt Project Dependencies Shown in IDEA
  • 18. IDEA deploy dependencies before run
  • 19. 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
  • 20. Thank you!