Sbt for mere mortals
Upcoming SlideShare
Loading in...5
×
 

Sbt for mere mortals

on

  • 377 views

 

Statistics

Views

Total Views
377
Views on SlideShare
375
Embed Views
2

Actions

Likes
1
Downloads
1
Comments
0

1 Embed 2

https://twitter.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

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 for mere mortals Sbt for mere mortals Presentation Transcript

  • SBTfor mere mortals
  • Whats inside?● Where did my XML go?● How does it work?● Where do the files go● Whats up with all the operators?● Creating plugins● And now?● Wordnik services
  • Where did my XML go?Short answer:awayLong answer:I hope it stays there
  • How does it work● Keys ○ Names for properties: setting key ○ Names for tasks: task key, input task key● Containers for keys: ○ projects ○ build ○ plugin● Configurations: ○ Kind of like package names in regular code in that they provide namespacing ○ Can have different classpath and dependency information
  • How does it work?Scopes really tie the thing together.Keys get values attached to them at scopeaxesSaying: name := "awesomest-project-ever"is really the same as saying name in This := "awesomest-..."the task compile refers to:compile in (Compile, This)
  • Where do the files go./*.sbt and project/*.scala both belong to the same build.The ./*.sbt files provide settings for theproject defined with base = file(".")module/something/*.sbt provides settings fora submodule defined in project/build.scalawith base = file("modules/something")
  • Where do the files goGlobal settings for a user:~/.sbt/sbt.version/*.sbtGlobal plugins for a user:~/.sbt/sbt.version//plugins/*.sbt and ~/.sbt/sbt.version//plugin/project/*.scalaPlugins local to a project:project/*.sbt and project/project/*.scala
  • Whats up with all the operators? := set a value of a property from a value += add a value to a key that is a list++= add a list of values to a key that is a list ~= update a value with a function T => T<<= set a value of a property from a sbt value<+= add a value of a property from a sbt value<++= adds a list of values like <+=
  • Creating a projectEither use ./build.sbt directlyor create a project/build.scalaobject MyBuild extends Build { lazy val root = Project( id = "friendly-name-for-project", base = file(".") // place to look for files )}
  • Adding dependenciesRequiring full name with version modifier:"org.json4s" % "json4s-jackson_2.10" %"3.1.0"Name only, no version modifier:"org.json4s" %% "json4s-jackson" % "3.1.0"
  • DependenciesExcluding items"com.amazon" % "aws-jdk" % "3.3.1" exclude("org.apache.httpcomponents", "httpclient")Intransitive"com.mongodb" %% "casbah" % "2.5.0" instransitive()Classifier"com.mongodb" %% "casbah" % "2.5.0" classifier("wordnik")
  • Creating a pluginwriting an sbt plugin or a build file are thesame thing. The plugin is reusable andsharable across many projects. Other thanthat they are the same.If you can write it in a class you can write it insbt, its a matter of seeing the translation andbreaking it apart in context + behavior, likemost other things Scala.
  • Creating a pluginclass Greeter(greeting: String) { def greet( name: String, from: String, log: String => Unit) = log( greeting + " " + name + " from " + from)}
  • Creating a pluginKeys: val objKey = SettingKey[Greeter]("greeter") val taskKey = TaskKey[Unit]("greet")Settings: objKey := new Greeter("Hello") name in taskKey := "Ivan" taskKey <<= (name in taskKey, name, objKey,streams) {(theName, from, obj, s) => obj.greet(theName, from, s.log.info(_) }
  • Creating a pluginWrap those up in an object that extendsPlugin and put those settings in a Seq[Setting[_]] and youre good to go, youve gota plugin.
  • Creating a pluginHOMEWORK:Try to create a plugin that will display thelatest tweet for a user given a user namefrom an sbt setting.or instead of a tweet, try downloading the listof open issues from jira when credentials areprovided.
  • And now?Go forth and build awesome stuff?Youll probably want to look at the sbt.Keysfile, to see what all the keys are that arecurrently defined.Read the source of many other plugins, sothat they no longer appear to do magic.