SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn
Getting Started with SBT
Ikenna Nwaiwu
Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn
What is SBT ?
Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn
Objectives
• Compile and run code with SBT
• Add managed dependencies to your project
• Run tests
• Publish to a binary repository
• Use a plugin
• Assemble an run a project jar
• Open an SBT project in Intellij
• Write and SBT task
Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn
Task 1:Write a HelloWorld file
• Create a HelloWorld programe in file “HelloWorld.scala”
• Compile it with >scalac
• Run it with >scala HelloWorld
Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn
Task 2: Now lets use SBT for building
• Create a file build.sbt
• Add the following to your sbt file
• name := "Helloworld project”
• version := "1.0"
• - Double space between lines
• Now start sbt in the directory and run >compile and >run
• >exit
Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn
Task 2: SBT for building – ignoring the target
directory
• SBT puts in generated classes and files in the target directory
• You can clean this directory : >clean
• If you use version control, you probably don’t want these files versioned.
Ignore them with .gitignore
$>’echo target/ ‘ > .gitignore
$>git init
$>git status
Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn
Task 3: Lets create the project directory
structure
• Move your HelloWorlds.scala file to
the src/main/scala folder
lib/
src/
main/
resources/
scala/
java/
test/
resources/
scala/
java/
Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn
Task 4: Add a project dependency
• Got to http://www.scalatest.org/install and
add the scalatest project dependency.
• Run > reload
• Run > update
• Run > test
Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn
Task 5: Write a test and run it
import org.scalatest.{FunSuite, Matchers}
class HelloWorldTest extends FunSuite with Matchers {
test("Multiplication"){
val result = HelloWorld.multiply(3, 4)
result shouldBe 12
}
}
• Create a file HelloWorldTest in
src/test/scala/HelloWorldTest.scala
• Now run > test
• What do you get ?
• Implement the missing method in
HelloWorld.scala
• Now run tests again
Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn
Task 6: Using the console and help
• The SBT console loads your project and allows
you invoke your methods and functions from
the command line
• >console
• >scala>:quit
• >help
• >help reload
Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn
Task 6: Publishing your project locally
• Publishing a project: uploading a descriptor (Ivy file or Maven POM) and jar , to
a repository so that other projects can specify your project as a dependency.
• Add the following to your build.sbt
organization := ”com.lagosscala"
• >publishLocal
• You can now create another project and include your HelloWorld code as a
dependency with
libraryDependencies += ”com.lagosscala” %% "helloworld-project" % “1.0”
Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn
Task 7: Adding a plugin to your project
• A plugin can be used to add more tasks to your project
• Lets add a plugin that packages our project with all the dependencies required for
executing it
• sbt assembly - https://github.com/sbt/sbt-assembly
• Create file project/assembly.sbt and add the following addSbtPlugin("com.eed3si9n"
% "sbt-assembly" % "0.14.3”)
• Now reload, update, and run >assembly
• Note the path of the created assembly jar. Can you run it with
java –jar /path/to/project-assembly.jar ?
Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn
Task 8: Open the project in Intellij
• File > Open > Project
• Use the ‘rebuild’ in the sbt pane to reload the project when you need to.
‘Auto import’ detects file changes and does this automatically as well.
Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn
Sbt Concepts: Settings
• An SBT project consists of an immutable map of key- value pairs
• An sbt build definition file, lists Settings (objects of Setting[T]).These are a list of transformations that can be
applied to the sbt project map. For example, they can add an entry to a map or transform an existing entry.
• The sbt build definition is a list of ‘Setting’s.
• A Setting is created by calling methods :=, +=, or ++= on a SettingKey and assigning a value.
• There are 3 kinds of Keys = SettingKey[T], InputKey[T] andTaskKey[T].
• SettingKeys – key for values computed once
• TaskKey – key for value recomputed each time
• InputKey – key for task that takes command line arguments as input
• There are built in keys that come with sbt and these are defined in sbt.Keys._
• You can create a custom key and use that for custom Settings e.g:
• lazy val helloWorld = taskKey[Unit](“My Hello World set task“)
• hello := { println("Hello World!”) }

Weitere ähnliche Inhalte

Was ist angesagt?

Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with GradleRyan Cuprak
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with MavenSid Anand
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolvedBhagwat Kumar
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin WritingSchalk Cronjé
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeansRyan Cuprak
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsGR8Conf
 
Building Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksBuilding Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksMike Hugo
 
Gradle For Beginners (Serbian Developer Conference 2013 english)
Gradle For Beginners (Serbian Developer Conference 2013 english)Gradle For Beginners (Serbian Developer Conference 2013 english)
Gradle For Beginners (Serbian Developer Conference 2013 english)Joachim Baumann
 
Java build tool_comparison
Java build tool_comparisonJava build tool_comparison
Java build tool_comparisonManav Prasad
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO DevsWO Community
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache AntShih-Hsiang Lin
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules uploadRyan Cuprak
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Rajmahendra Hegde
 
Grails Plugin Best Practices
Grails Plugin Best PracticesGrails Plugin Best Practices
Grails Plugin Best PracticesBurt Beckwith
 

Was ist angesagt? (20)

Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin Writing
 
Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails Projects
 
Building Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksBuilding Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And Tricks
 
Gradle For Beginners (Serbian Developer Conference 2013 english)
Gradle For Beginners (Serbian Developer Conference 2013 english)Gradle For Beginners (Serbian Developer Conference 2013 english)
Gradle For Beginners (Serbian Developer Conference 2013 english)
 
GradleFX
GradleFXGradleFX
GradleFX
 
Java build tool_comparison
Java build tool_comparisonJava build tool_comparison
Java build tool_comparison
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache Ant
 
COScheduler
COSchedulerCOScheduler
COScheduler
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
Play framework
Play frameworkPlay framework
Play framework
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
 
Apache Lucene for Java EE Developers
Apache Lucene for Java EE DevelopersApache Lucene for Java EE Developers
Apache Lucene for Java EE Developers
 
Grails Plugin Best Practices
Grails Plugin Best PracticesGrails Plugin Best Practices
Grails Plugin Best Practices
 

Andere mochten auch

Sbt tutorial
Sbt tutorialSbt tutorial
Sbt tutorialGary Gai
 
MY SIX MONTHS I T REPORT
MY SIX MONTHS I T REPORTMY SIX MONTHS I T REPORT
MY SIX MONTHS I T REPORTIkenna Onyeama
 
Logbook For Industrial Supervision and Training- A Look at Paper and Digital ...
Logbook For Industrial Supervision and Training- A Look at Paper and Digital ...Logbook For Industrial Supervision and Training- A Look at Paper and Digital ...
Logbook For Industrial Supervision and Training- A Look at Paper and Digital ...Olufemi Jeremiah Olubodun
 
Indusrial trainning Report presentation
Indusrial trainning Report presentationIndusrial trainning Report presentation
Indusrial trainning Report presentationAbdulafeez Fasasi
 

Andere mochten auch (9)

SBT Made Simple
SBT Made SimpleSBT Made Simple
SBT Made Simple
 
Sbt tutorial
Sbt tutorialSbt tutorial
Sbt tutorial
 
A day with sbt
A day with sbtA day with sbt
A day with sbt
 
SIWES Presentation
SIWES PresentationSIWES Presentation
SIWES Presentation
 
my It report
 my It report my It report
my It report
 
MY SIX MONTHS I T REPORT
MY SIX MONTHS I T REPORTMY SIX MONTHS I T REPORT
MY SIX MONTHS I T REPORT
 
I.T. Report
I.T. ReportI.T. Report
I.T. Report
 
Logbook For Industrial Supervision and Training- A Look at Paper and Digital ...
Logbook For Industrial Supervision and Training- A Look at Paper and Digital ...Logbook For Industrial Supervision and Training- A Look at Paper and Digital ...
Logbook For Industrial Supervision and Training- A Look at Paper and Digital ...
 
Indusrial trainning Report presentation
Indusrial trainning Report presentationIndusrial trainning Report presentation
Indusrial trainning Report presentation
 

Ähnlich wie Getting started with sbt

"Project Tye to Tie .NET Microservices", Oleg Karasik
"Project Tye to Tie .NET Microservices", Oleg Karasik"Project Tye to Tie .NET Microservices", Oleg Karasik
"Project Tye to Tie .NET Microservices", Oleg KarasikFwdays
 
4.Building a Data Product using apache Zeppelin - Apache Kylin Meetup @Shanghai
4.Building a Data Product using apache Zeppelin - Apache Kylin Meetup @Shanghai4.Building a Data Product using apache Zeppelin - Apache Kylin Meetup @Shanghai
4.Building a Data Product using apache Zeppelin - Apache Kylin Meetup @ShanghaiLuke Han
 
In this project, you will learn to use some of the team” features o.docx
In this project, you will learn to use some of the team” features o.docxIn this project, you will learn to use some of the team” features o.docx
In this project, you will learn to use some of the team” features o.docxbreaksdayle
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Derek Jacoby
 
Version control git day01
Version control   git day01Version control   git day01
Version control git day01Gourav Varma
 
Version control git day01
Version control   git day01Version control   git day01
Version control git day01Gourav Varma
 
Reproducible research: practice
Reproducible research: practiceReproducible research: practice
Reproducible research: practiceC. Tobin Magle
 
Eclipse IDE, 2019.09, Java Development
Eclipse IDE, 2019.09, Java Development Eclipse IDE, 2019.09, Java Development
Eclipse IDE, 2019.09, Java Development Pei-Hsuan Hsieh
 
Make an Instant Website with Webhooks
Make an Instant Website with WebhooksMake an Instant Website with Webhooks
Make an Instant Website with WebhooksAnne Gentle
 
SharePoint for Project Management (2016)
SharePoint for Project Management (2016)SharePoint for Project Management (2016)
SharePoint for Project Management (2016)wandersick
 
[2015/2016] Collaborative software development with Git
[2015/2016] Collaborative software development with Git[2015/2016] Collaborative software development with Git
[2015/2016] Collaborative software development with GitIvano Malavolta
 
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015Mike Broberg
 
Introducing to git
Introducing to gitIntroducing to git
Introducing to gitSajjad Rad
 

Ähnlich wie Getting started with sbt (20)

Jenkins CI
Jenkins CIJenkins CI
Jenkins CI
 
Simple build tool
Simple build toolSimple build tool
Simple build tool
 
Web works hol
Web works holWeb works hol
Web works hol
 
"Project Tye to Tie .NET Microservices", Oleg Karasik
"Project Tye to Tie .NET Microservices", Oleg Karasik"Project Tye to Tie .NET Microservices", Oleg Karasik
"Project Tye to Tie .NET Microservices", Oleg Karasik
 
4.Building a Data Product using apache Zeppelin - Apache Kylin Meetup @Shanghai
4.Building a Data Product using apache Zeppelin - Apache Kylin Meetup @Shanghai4.Building a Data Product using apache Zeppelin - Apache Kylin Meetup @Shanghai
4.Building a Data Product using apache Zeppelin - Apache Kylin Meetup @Shanghai
 
In this project, you will learn to use some of the team” features o.docx
In this project, you will learn to use some of the team” features o.docxIn this project, you will learn to use some of the team” features o.docx
In this project, you will learn to use some of the team” features o.docx
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9
 
Version control git day01
Version control   git day01Version control   git day01
Version control git day01
 
Version control git day01
Version control   git day01Version control   git day01
Version control git day01
 
Reproducible research: practice
Reproducible research: practiceReproducible research: practice
Reproducible research: practice
 
Eclipse IDE, 2019.09, Java Development
Eclipse IDE, 2019.09, Java Development Eclipse IDE, 2019.09, Java Development
Eclipse IDE, 2019.09, Java Development
 
Make an Instant Website with Webhooks
Make an Instant Website with WebhooksMake an Instant Website with Webhooks
Make an Instant Website with Webhooks
 
SharePoint for Project Management (2016)
SharePoint for Project Management (2016)SharePoint for Project Management (2016)
SharePoint for Project Management (2016)
 
[2015/2016] Collaborative software development with Git
[2015/2016] Collaborative software development with Git[2015/2016] Collaborative software development with Git
[2015/2016] Collaborative software development with Git
 
Makefile+VersionControl
Makefile+VersionControlMakefile+VersionControl
Makefile+VersionControl
 
Developer@sky
Developer@skyDeveloper@sky
Developer@sky
 
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
 
Introducing to git
Introducing to gitIntroducing to git
Introducing to git
 
Assignment 2
Assignment 2Assignment 2
Assignment 2
 
R meetup 20161011v2
R meetup 20161011v2R meetup 20161011v2
R meetup 20161011v2
 

Kürzlich hochgeladen

Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 

Kürzlich hochgeladen (20)

Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 

Getting started with sbt

  • 1. Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn Getting Started with SBT Ikenna Nwaiwu
  • 2. Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn What is SBT ?
  • 3. Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn Objectives • Compile and run code with SBT • Add managed dependencies to your project • Run tests • Publish to a binary repository • Use a plugin • Assemble an run a project jar • Open an SBT project in Intellij • Write and SBT task
  • 4. Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn Task 1:Write a HelloWorld file • Create a HelloWorld programe in file “HelloWorld.scala” • Compile it with >scalac • Run it with >scala HelloWorld
  • 5. Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn Task 2: Now lets use SBT for building • Create a file build.sbt • Add the following to your sbt file • name := "Helloworld project” • version := "1.0" • - Double space between lines • Now start sbt in the directory and run >compile and >run • >exit
  • 6. Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn Task 2: SBT for building – ignoring the target directory • SBT puts in generated classes and files in the target directory • You can clean this directory : >clean • If you use version control, you probably don’t want these files versioned. Ignore them with .gitignore $>’echo target/ ‘ > .gitignore $>git init $>git status
  • 7. Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn Task 3: Lets create the project directory structure • Move your HelloWorlds.scala file to the src/main/scala folder lib/ src/ main/ resources/ scala/ java/ test/ resources/ scala/ java/
  • 8. Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn Task 4: Add a project dependency • Got to http://www.scalatest.org/install and add the scalatest project dependency. • Run > reload • Run > update • Run > test
  • 9. Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn Task 5: Write a test and run it import org.scalatest.{FunSuite, Matchers} class HelloWorldTest extends FunSuite with Matchers { test("Multiplication"){ val result = HelloWorld.multiply(3, 4) result shouldBe 12 } } • Create a file HelloWorldTest in src/test/scala/HelloWorldTest.scala • Now run > test • What do you get ? • Implement the missing method in HelloWorld.scala • Now run tests again
  • 10. Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn Task 6: Using the console and help • The SBT console loads your project and allows you invoke your methods and functions from the command line • >console • >scala>:quit • >help • >help reload
  • 11. Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn Task 6: Publishing your project locally • Publishing a project: uploading a descriptor (Ivy file or Maven POM) and jar , to a repository so that other projects can specify your project as a dependency. • Add the following to your build.sbt organization := ”com.lagosscala" • >publishLocal • You can now create another project and include your HelloWorld code as a dependency with libraryDependencies += ”com.lagosscala” %% "helloworld-project" % “1.0”
  • 12. Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn Task 7: Adding a plugin to your project • A plugin can be used to add more tasks to your project • Lets add a plugin that packages our project with all the dependencies required for executing it • sbt assembly - https://github.com/sbt/sbt-assembly • Create file project/assembly.sbt and add the following addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.3”) • Now reload, update, and run >assembly • Note the path of the created assembly jar. Can you run it with java –jar /path/to/project-assembly.jar ?
  • 13. Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn Task 8: Open the project in Intellij • File > Open > Project • Use the ‘rebuild’ in the sbt pane to reload the project when you need to. ‘Auto import’ detects file changes and does this automatically as well.
  • 14. Ikenna Consulting ikenna@ikenna.net Twitter: @ikennacn Sbt Concepts: Settings • An SBT project consists of an immutable map of key- value pairs • An sbt build definition file, lists Settings (objects of Setting[T]).These are a list of transformations that can be applied to the sbt project map. For example, they can add an entry to a map or transform an existing entry. • The sbt build definition is a list of ‘Setting’s. • A Setting is created by calling methods :=, +=, or ++= on a SettingKey and assigning a value. • There are 3 kinds of Keys = SettingKey[T], InputKey[T] andTaskKey[T]. • SettingKeys – key for values computed once • TaskKey – key for value recomputed each time • InputKey – key for task that takes command line arguments as input • There are built in keys that come with sbt and these are defined in sbt.Keys._ • You can create a custom key and use that for custom Settings e.g: • lazy val helloWorld = taskKey[Unit](“My Hello World set task“) • hello := { println("Hello World!”) }

Hinweis der Redaktion

  1. Note that SBT can run interactively or in batch mode >sbt compile run Note we are using ‘bare build definitions’ (pre 0.13.7) 1. Multi-project .sbt build definition 2. Bare .sbt build definition 3. .scala build definition
  2. Note that SBT can run interactively or in batch mode >sbt compile run
  3. Note that SBT can run interactively or in batch mode Also note target and project are top level directories
  4. libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % "test"
  5. Just tests first
  6. >console You can run scala code on the console >scala> HelloWorld.multiply(4, 6)