SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
SBT
for mere mortals
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
Where did my XML go?
Short answer:
away

Long 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 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)
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")
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
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 <+=
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
  )
}
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"
Dependencies
Excluding 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 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.
Creating a plugin
class Greeter(greeting: String) {
  def greet(
             name: String,
             from: String,
             log: String => Unit) =
    log(
      greeting + " " + name + " from " + from)
}
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(_) }
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.
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.
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.

Weitere ähnliche Inhalte

Was ist angesagt?

Understanding reactive programming with microsoft reactive extensions
Understanding reactive programming  with microsoft reactive extensionsUnderstanding reactive programming  with microsoft reactive extensions
Understanding reactive programming with microsoft reactive extensionsOleksandr Zhevzhyk
 
(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...
(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...
(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...Amazon Web Services
 
More Data, More Problems: Evolving big data machine learning pipelines with S...
More Data, More Problems: Evolving big data machine learning pipelines with S...More Data, More Problems: Evolving big data machine learning pipelines with S...
More Data, More Problems: Evolving big data machine learning pipelines with S...Alex Sadovsky
 
Automation in angular js
Automation in angular jsAutomation in angular js
Automation in angular jsMarcin Wosinek
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionJesus Manuel Olivas
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitVaclav Pech
 
GPars howto - when to use which concurrency abstraction
GPars howto - when to use which concurrency abstractionGPars howto - when to use which concurrency abstraction
GPars howto - when to use which concurrency abstractionVaclav Pech
 
Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaFlorent Pillet
 
Fullstack Conference - Proxies before proxies: The hidden gems of Javascript...
Fullstack Conference -  Proxies before proxies: The hidden gems of Javascript...Fullstack Conference -  Proxies before proxies: The hidden gems of Javascript...
Fullstack Conference - Proxies before proxies: The hidden gems of Javascript...Tim Chaplin
 
Scala for the web Lightning Talk
Scala for the web Lightning TalkScala for the web Lightning Talk
Scala for the web Lightning TalkGiltTech
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVMVaclav Pech
 
Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#Riccardo Terrell
 

Was ist angesagt? (20)

Q
QQ
Q
 
Group111
Group111Group111
Group111
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 
Understanding reactive programming with microsoft reactive extensions
Understanding reactive programming  with microsoft reactive extensionsUnderstanding reactive programming  with microsoft reactive extensions
Understanding reactive programming with microsoft reactive extensions
 
(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...
(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...
(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...
 
Gpars workshop
Gpars workshopGpars workshop
Gpars workshop
 
More Data, More Problems: Evolving big data machine learning pipelines with S...
More Data, More Problems: Evolving big data machine learning pipelines with S...More Data, More Problems: Evolving big data machine learning pipelines with S...
More Data, More Problems: Evolving big data machine learning pipelines with S...
 
Automation in angular js
Automation in angular jsAutomation in angular js
Automation in angular js
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 Edition
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruit
 
Reason and GraphQL
Reason and GraphQLReason and GraphQL
Reason and GraphQL
 
GPars howto - when to use which concurrency abstraction
GPars howto - when to use which concurrency abstractionGPars howto - when to use which concurrency abstraction
GPars howto - when to use which concurrency abstraction
 
Python my SQL - create table
Python my SQL - create tablePython my SQL - create table
Python my SQL - create table
 
Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoa
 
Concurrecny inf sharp
Concurrecny inf sharpConcurrecny inf sharp
Concurrecny inf sharp
 
Play á la Rails
Play á la RailsPlay á la Rails
Play á la Rails
 
Fullstack Conference - Proxies before proxies: The hidden gems of Javascript...
Fullstack Conference -  Proxies before proxies: The hidden gems of Javascript...Fullstack Conference -  Proxies before proxies: The hidden gems of Javascript...
Fullstack Conference - Proxies before proxies: The hidden gems of Javascript...
 
Scala for the web Lightning Talk
Scala for the web Lightning TalkScala for the web Lightning Talk
Scala for the web Lightning Talk
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#
 

Andere mochten auch

משמעות הספרות
משמעות הספרותמשמעות הספרות
משמעות הספרותguest6afe24
 
What's Next in Growth? 2016
What's Next in Growth? 2016What's Next in Growth? 2016
What's Next in Growth? 2016Andrew Chen
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your BusinessBarry Feldman
 

Andere mochten auch (6)

Ruby Loves Dot Net
Ruby Loves Dot NetRuby Loves Dot Net
Ruby Loves Dot Net
 
משמעות הספרות
משמעות הספרותמשמעות הספרות
משמעות הספרות
 
Scalatra 2.2
Scalatra 2.2Scalatra 2.2
Scalatra 2.2
 
IronRuby - Fosdem 2010
IronRuby - Fosdem 2010IronRuby - Fosdem 2010
IronRuby - Fosdem 2010
 
What's Next in Growth? 2016
What's Next in Growth? 2016What's Next in Growth? 2016
What's Next in Growth? 2016
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
 

Ähnlich wie Sbt for mere mortals

Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
ES3-2020-P3 TDD Calculator
ES3-2020-P3 TDD CalculatorES3-2020-P3 TDD Calculator
ES3-2020-P3 TDD CalculatorDavid Rodenas
 
The Ring programming language version 1.6 book - Part 40 of 189
The Ring programming language version 1.6 book - Part 40 of 189The Ring programming language version 1.6 book - Part 40 of 189
The Ring programming language version 1.6 book - Part 40 of 189Mahmoud Samir Fayed
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingSchalk Cronjé
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBMongoDB
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingSchalk Cronjé
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbtFabio Fumarola
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderAndres Almiray
 
Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4DEVCON
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Tino Isnich
 
The Ring programming language version 1.5.2 book - Part 6 of 181
The Ring programming language version 1.5.2 book - Part 6 of 181The Ring programming language version 1.5.2 book - Part 6 of 181
The Ring programming language version 1.5.2 book - Part 6 of 181Mahmoud Samir Fayed
 

Ähnlich wie Sbt for mere mortals (20)

Angular Schematics
Angular SchematicsAngular Schematics
Angular Schematics
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
ES3-2020-P3 TDD Calculator
ES3-2020-P3 TDD CalculatorES3-2020-P3 TDD Calculator
ES3-2020-P3 TDD Calculator
 
The Ring programming language version 1.6 book - Part 40 of 189
The Ring programming language version 1.6 book - Part 40 of 189The Ring programming language version 1.6 book - Part 40 of 189
The Ring programming language version 1.6 book - Part 40 of 189
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin Writing
 
Devtools cheatsheet
Devtools cheatsheetDevtools cheatsheet
Devtools cheatsheet
 
Devtools cheatsheet
Devtools cheatsheetDevtools cheatsheet
Devtools cheatsheet
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin Writing
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilder
 
Why ruby
Why rubyWhy ruby
Why ruby
 
Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4
 
Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01
 
Sbt
SbtSbt
Sbt
 
The Ring programming language version 1.5.2 book - Part 6 of 181
The Ring programming language version 1.5.2 book - Part 6 of 181The Ring programming language version 1.5.2 book - Part 6 of 181
The Ring programming language version 1.5.2 book - Part 6 of 181
 

Sbt for mere mortals

  • 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"
  • 11. Dependencies Excluding 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")
  • 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.