What are the three scope axes that affect which key definition is used? projects, configurations, and tasks

What is meant by project scope? Which project you're working on, e.g. hello-world vs todo-list.

What is meant by configuration scope? The context for the task being performed, e.g. test vs. compile, e.g. the classpath may be different when building src/main vs. src/test.

What is meant by task scope? The specific task being performed, e.g. package-options might be different for the package-src task vs. the package-bin task.

What is Global scope? A key definition may be specific to a particular value along an axis, e.g. may be defined for test configuration only, or it may be Global with respect to configuration, and have the same value for all configurations.

What value is used for a key if it is not defined for a specific scope? Fall back to the Global or entire-build value.

What is the syntax for a scoped key? {project-url}project/configuration:key(for task)

e.g. {file:///home/george/hello}default-aae33/compile:full-classpath(for doc)

How do you represent Global scope for an axis when specifying a key value? *

What is the sbt repl command to view details about a key? inspect

How do you specify scope when setting a key in build.sbt? Use 'in' keyword, e.g., to use the Compile configuration:



name in Compile := "hello"



or to use the packageBin task:



name in packageBin := "hello"



(don't know how it determines whether config or task)

How do you specify that a setting applies to all projects in a .sbt file? Use 'global' keyword:



name in Global := "hello"



Config and task are Global by default. Project is current project by default.

A build definition creates a list of _. Setting's

What is a Setting? A transformation that modifies the build definition, which is a map of key-value pairs.

What does operator := do? Replaces a key's value in the build map.

What do operators += and++= do? Concatenate either a value or a sequence of values to a key's existing value.

What does operator ~= do? Applies a function to a key's value.

What does operator <<= do? Creates a new value for a key based on the value(s) of other key(s). E.g.:



organization <<= name

If you use operator <<= to base a key's value on another key, you create a _ on that key. dependency

What is the type of the argument for <<=? Initialize[T], where T is the type of the value being set. (Keys extend the Initialize trait, and so may be used directly on the right side of the <<=.)

Show an example of using <<= to create a dependency on multiple keys. name <<= (name, version){(n, v) => n + ":" + v}

Show an example of using ~= to modify a value, using placeholder notation. name ~= { _.toUpperCase }

or

name ~= ( _.toUpperCase )



How do you set a Task value from a Setting when using <<=? Use the map function instead of apply.

How do you set a Setting value from a Task? You can't. Settings are computed once at startup, while tasks are re-run every time.

How do you create an alias? Use <<=. (:= won't work)

How do you append to a value based on the values of other keys? Use <+= or <++=.

How to provide an unmanaged library dependency? Put jar in lib directory.

How to display the value of a key from sbt prompt? show <key name>, e.g.:

show dependency-classpath

What is the key for the project's root directory? base-directory (SettingKey is baseDirectory)

How to add a managed dependency? libraryDependencies += groupId % artifactId % revision

Where is the local repository for managed dependencies? ~/.ivy2/cache

How to add multiple dependencies in one statement? libraryDependencies ++= Seq(

group1 % artifact1 % revision1,

group2 % artifact2 % revision2

)

What does %% do when specifying dependencies? When used between the group id and artifact id, it appends the scala version to the artifact id. (Just a shortcut for adding it manually

to the artifact id, e.g. "scalatest_2.9.1".)

How to specify the latest revision of an artifact? Use "latest.integration" instead of a revision number.

How to add a repository? Append to 'resolvers' key.

How to add a configuration to a dependency? Append it with a '%', e.g.:

libraryDependencies += "org.apache.derby" % "derby" % "10.4.1.3" % "test"

How to add a Setting to a .scala file so that it has project scope? (show example) Include it in the settings parameter when calling Project(), e.g.:

settings = Project.defaultSettings ++ Seq(sampleKeyB := "foo")

How to add a Setting to a .scala file so that it has build scope? Override the 'settings' val in the Build object and append Setting to it like so:

override lazy val settings = super.settings ++ Seq([settingKey] := [value])

How to add a Setting to a .sbt file so it has build scope? Specify "in ThisBuild", e.g.:

sampleKeyC in ThisBuild := "foo"

How to add a Setting to a .sbt file so it has project scope? Don't specify a scope when setting value -- project scope is default. E.g.:

sampleKeyC := "foo"

If a value is set in both a Build object and in a .sbt file, which value is used? The one in the .sbt file. .sbt settings are appended to the settings from

the Build objects.

How is it that val's from Build objects are available for use within the .sbt file? All contents of Build objects are imported into the .sbt file by default.

In .scala files, you can add settings to _ to make them build-scoped. Build.settings

In .scala files, you can add settings to _ to make them project-scoped. Project.settings, as an argument 'settings = ...' in call to Project() method.

Any _ you write in a .scala file will have its contents imported and available to .sbt files. 'Build' object.

The settings in .sbt files are _ to the settings in .scala files. appended

The settings in .sbt files are _-scoped by default. project