2. What's inside?
● Where did my XML go?
● How does it work?
● Where do the files go
● What's up with all the operators?
● Creating plugins
● And now?
● Wordnik services
3. Where did my XML go?
Short answer:
away
Long answer:
I hope it stays there
4. 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
5. How does it work?
Scopes really tie the thing together.
Keys get values attached to them at scope
axes
Saying:
name := "awesomest-project-ever"
is really the same as saying
name in This := "awesomest-..."
the task compile refers to:
compile in (Compile, This)
6. Where do the files go
./*.sbt and project/*.scala
both belong to the same build.
The ./*.sbt files provide settings for the
project defined with base = file(".")
module/something/*.sbt provides settings for
a submodule defined in project/build.scala
with base = file("modules/something")
7. Where do the files go
Global settings for a user:
~/.sbt/sbt.version/*.sbt
Global plugins for a user:
~/.sbt/sbt.version//plugins/*.sbt and ~/.
sbt/sbt.version//plugin/project/*.scala
Plugins local to a project:
project/*.sbt and project/project/*.scala
8. What's 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 <+=
9. Creating a project
Either use ./build.sbt directly
or create a project/build.scala
object MyBuild extends Build {
lazy val root = Project(
id = "friendly-name-for-project",
base = file(".") // place to look for files
)
}
10. Adding dependencies
Requiring 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"
12. Creating a plugin
writing an sbt plugin or a build file are the
same thing. The plugin is reusable and
sharable across many projects. Other than
that they are the same.
If you can write it in a class you can write it in
sbt, it's a matter of seeing the translation and
breaking it apart in context + behavior, like
most other things Scala.
13. Creating a plugin
class Greeter(greeting: String) {
def greet(
name: String,
from: String,
log: String => Unit) =
log(
greeting + " " + name + " from " + from)
}
14. Creating a plugin
Keys:
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(_) }
15. Creating a plugin
Wrap those up in an object that extends
Plugin and put those settings in a Seq
[Setting[_]] and you're good to go, you've got
a plugin.
16. Creating a plugin
HOMEWORK:
Try to create a plugin that will display the
latest tweet for a user given a user name
from an sbt setting.
or instead of a tweet, try downloading the list
of open issues from jira when credentials are
provided.
17. And now?
Go forth and build awesome stuff?
You'll probably want to look at the sbt.Keys
file, to see what all the keys are that are
currently defined.
Read the source of many other plugins, so
that they no longer appear to do magic.