SlideShare a Scribd company logo
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!”) }

More Related Content

What's hot

Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
Ryan Cuprak
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
Sid Anand
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
Bhagwat Kumar
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin Writing
Schalk Cronjé
 
Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
Jeevesh Pandey
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
Ryan 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 Projects
GR8Conf
 
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
 
GradleFX
GradleFXGradleFX
Java build tool_comparison
Java build tool_comparisonJava build tool_comparison
Java build tool_comparison
Manav 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 Ant
Shih-Hsiang Lin
 
COScheduler
COSchedulerCOScheduler
COScheduler
WO Community
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
Ryan 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 2012
Rajmahendra Hegde
 
Apache Lucene for Java EE Developers
Apache Lucene for Java EE DevelopersApache Lucene for Java EE Developers
Apache Lucene for Java EE Developers
Virtual JBoss User Group
 
Grails Plugin Best Practices
Grails Plugin Best PracticesGrails Plugin Best Practices
Grails Plugin Best Practices
Burt Beckwith
 

What's hot (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
 

Viewers also liked

SBT Made Simple
SBT Made SimpleSBT Made Simple
SBT Made Simple
Fuqiang Wang
 
Sbt tutorial
Sbt tutorialSbt tutorial
Sbt tutorial
Gary Gai
 
A day with sbt
A day with sbtA day with sbt
A day with sbt
Marcus Lönnberg
 
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 presentation
Abdulafeez Fasasi
 

Viewers also liked (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
 

Similar to Getting started with sbt

Jenkins CI
Jenkins CIJenkins CI
Jenkins CI
Viyaan Jhiingade
 
Simple build tool
Simple build toolSimple build tool
Simple build tool
Knoldus Inc.
 
"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
Fwdays
 
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
Luke 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.docx
breaksdayle
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9
Derek Jacoby
 
Version control git day01
Version control   git day01Version control   git day01
Version control git day01
Gourav Varma
 
Version control git day01
Version control   git day01Version control   git day01
Version control git day01
Gourav Varma
 
Reproducible research: practice
Reproducible research: practiceReproducible research: practice
Reproducible research: practice
C. 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 Webhooks
Anne 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 Git
Ivano Malavolta
 
Developer@sky
Developer@skyDeveloper@sky
Developer@sky
Claudia Danciu
 
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
Mike Broberg
 
Introducing to git
Introducing to gitIntroducing to git
Introducing to git
Sajjad Rad
 
R meetup 20161011v2
R meetup 20161011v2R meetup 20161011v2
R meetup 20161011v2
Niels Ole Dam
 

Similar to 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
 

Recently uploaded

GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 

Recently uploaded (20)

GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 

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!”) }

Editor's Notes

  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)