sbt

SBT: Example build.sbt variables/settings (from PPrint) alvin August 31, 2017 - 9:47am

Because I think it’s often best to “learn by example,” I’ve become a connoisseur of SBT build.sbt examples, and this build.sbt file from Lihaoyi’s PPrint project demonstrates a lot of SBT variables:

SBT: 'compiler-interface' not yet compiled for Scala 2.12.2. Compiling... alvin August 18, 2017 - 6:34pm

SBT FAQ: What does the message, “'compiler-interface' not yet compiled for Scala 2.12.2. Compiling...” mean?

Answer: I don’t know all of the nitty-gritty details, but the short version of the answer is described in the SBT docs:

SBT: How to pass command line arguments to ‘sbt run’ alvin August 17, 2017 - 11:30am

Question: How do I pass command-line parameters to my Scala application when I’m running the application with SBT?

Solution: There are two different possible scenarios here:

SBT 1.0 is now available alvin August 11, 2017 - 8:01am

SBT 1.0.0 is now available. See this Lightbend page for more details.

How to start a Scala REPL session inside SBT (Simple Build Tool)

Scala FAQ: How do I start a Scala REPL session from SBT (i.e., inside the Simple Build Tool)?

Answer: Use console or consoleQuick:

  • Type console to start a REPL session from inside SBT. This (a) compiles your Scala project and then (b) starts a REPL session.
  • Type consoleQuick if you don’t want to compile your project before starting a REPL session inside of SBT.

The console command process looks like this:

> sbt
[info] Loading project definition from /Users/al/Projects/Cats101/project
[info] Set current project to Cats101 (in build file:/Users/al/Projects/Cats101/)

> console
[info] Starting scala interpreter...
[info]
Welcome to Scala 2.12.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.

scala> _

If you wanted to see how to start a Scala REPL session from inside SBT, I hope this helps.

How to use a Maven repository library with SBT

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 18.17, “Using a Maven Repository Library with SBT.”

Problem

When working on a Scala project built with SBT, you want to use a Java library that’s in a Maven repository, but the library doesn’t include information about how to use it with Scala and SBT.

SBT: How to get started using the Build.scala file (instead of build.sbt)

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 18.16, “Using Build.scala Instead of build.sbt.”

Problem

In an SBT project, you want to use the project/Build.scala file instead of build.sbt to define your Scala project, or you need some examples of how to use Build.scala to solve build problems that can’t be handled in build.sbt.

How to “publish” a Scala/SBT library

20.15. Publishing Your Library

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 18.15, “Publishing an SBT Library.”

Problem

You’ve created a Scala project or library with SBT that you want to share with other users, creating all the files you need for an Ivy repository.

How to resolve SBT problems by generating a stack trace

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 18.12, “Resolving Problems by Getting an SBT Stack Trace.”

Problem

In a Scala project, you’re trying to use SBT to compile, run, or package a project, and it’s failing, and you need to be able to see the stack trace to understand why it’s failing.