2012-09-15 00:08:35 +02:00
|
|
|
=========================================
|
|
|
|
|
Interacting with the Configuration System
|
|
|
|
|
=========================================
|
|
|
|
|
|
|
|
|
|
Central to sbt is the new configuration system, which is designed to
|
|
|
|
|
enable extensive customization. The goal of this page is to explain the
|
|
|
|
|
general model behind the configuration system and how to work with it.
|
|
|
|
|
The Getting Started Guide (see :doc:`.sbt files </Getting-Started/Basic-Def>`)
|
|
|
|
|
describes how to define settings; this page describes interacting
|
|
|
|
|
with them and exploring them at the command line.
|
|
|
|
|
|
|
|
|
|
Selecting commands, tasks, and settings
|
|
|
|
|
=======================================
|
|
|
|
|
|
|
|
|
|
A fully-qualified reference to a setting or task looks like:
|
|
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
|
|
|
|
{<build-uri>}<project-id>/config:inkey::key
|
|
|
|
|
|
2013-07-29 13:27:17 +02:00
|
|
|
This "scoped key" reference is used by commands like `last` and
|
|
|
|
|
`inspect` and when selecting a task to run. Only `key` is usually
|
2012-09-15 00:08:35 +02:00
|
|
|
required by the parser; the remaining optional pieces select the scope.
|
|
|
|
|
These optional pieces are individually referred to as scope axes. In the
|
2013-07-29 13:27:17 +02:00
|
|
|
above description, `{<build-uri>}` and `<project-id>/` specify the
|
|
|
|
|
project axis, `config:` is the configuration axis, and `inkey` is
|
2012-09-15 00:08:35 +02:00
|
|
|
the task-specific axis. Unspecified components are taken to be the
|
|
|
|
|
current project (project axis) or auto-detected (configuration and task
|
2013-07-29 13:27:17 +02:00
|
|
|
axes). An asterisk (`*`) is used to explicitly refer to the `Global`
|
|
|
|
|
context, as in `*/*:key`.
|
2012-09-15 00:08:35 +02:00
|
|
|
|
|
|
|
|
Selecting the configuration
|
|
|
|
|
---------------------------
|
|
|
|
|
|
|
|
|
|
In the case of an unspecified configuration (that is, when the
|
2013-07-29 13:27:17 +02:00
|
|
|
`config:` part is omitted), if the key is defined in `Global`, that
|
2012-09-15 00:08:35 +02:00
|
|
|
is selected. Otherwise, the first configuration defining the key is
|
|
|
|
|
selected, where order is determined by the project definition's
|
2013-07-29 13:27:17 +02:00
|
|
|
`configurations` member. By default, this ordering is
|
|
|
|
|
`compile, test, ...`
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2013-07-29 13:27:17 +02:00
|
|
|
For example, the following are equivalent when run in a project `root`
|
|
|
|
|
in the build in `/home/user/sample/`:
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
|
|
|
|
> compile
|
|
|
|
|
> compile:compile
|
|
|
|
|
> root/compile
|
|
|
|
|
> root/compile:compile
|
|
|
|
|
> {file:/home/user/sample/}root/compile:compile
|
|
|
|
|
|
2013-09-27 00:26:19 +02:00
|
|
|
As another example, :key:`run` by itself refers to `compile:run` because
|
|
|
|
|
there is no global :key:`run` task and the first configuration searched,
|
|
|
|
|
:key:`compile`, defines a :key:`run`. Therefore, to reference the :key:`run` task
|
|
|
|
|
for the `Test` configuration, the configuration axis must be specified
|
2013-07-29 13:27:17 +02:00
|
|
|
like `test:run`. Some other examples that require the explicit
|
|
|
|
|
`test:` axis:
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2012-11-19 02:29:01 +01:00
|
|
|
> test:consoleQuick
|
2012-09-15 00:08:35 +02:00
|
|
|
> test:console
|
|
|
|
|
> test:doc
|
|
|
|
|
> test:package
|
|
|
|
|
|
|
|
|
|
Task-specific Settings
|
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
|
|
Some settings are defined per-task. This is used when there are several
|
2013-09-27 00:26:19 +02:00
|
|
|
related tasks, such as :key:`package`, :key:`packageSrc`, and
|
|
|
|
|
:key:`packageDoc`, in the same configuration (such as :key:`compile` or
|
|
|
|
|
:key:`test`). For package tasks, their settings are the files to package,
|
2012-09-15 00:08:35 +02:00
|
|
|
the options to use, and the output file to produce. Each package task
|
|
|
|
|
should be able to have different values for these settings.
|
|
|
|
|
|
|
|
|
|
This is done with the task axis, which selects the task to apply a
|
|
|
|
|
setting to. For example, the following prints the output jar for the
|
|
|
|
|
different package tasks.
|
|
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2012-11-19 02:29:01 +01:00
|
|
|
> package::artifactPath
|
2012-09-15 00:08:35 +02:00
|
|
|
[info] /home/user/sample/target/scala-2.8.1.final/demo_2.8.1-0.1.jar
|
|
|
|
|
|
2012-11-19 02:29:01 +01:00
|
|
|
> packageSrc::artifactPath
|
2012-09-15 00:08:35 +02:00
|
|
|
[info] /home/user/sample/target/scala-2.8.1.final/demo_2.8.1-0.1-src.jar
|
|
|
|
|
|
2012-11-19 02:29:01 +01:00
|
|
|
> packageDoc::artifactPath
|
2012-09-15 00:08:35 +02:00
|
|
|
[info] /home/user/sample/target/scala-2.8.1.final/demo_2.8.1-0.1-doc.jar
|
|
|
|
|
|
2012-11-19 02:29:01 +01:00
|
|
|
> test:package::artifactPath
|
2012-09-15 00:08:35 +02:00
|
|
|
[info] /home/user/sample/target/scala-2.8.1.final/root_2.8.1-0.1-test.jar
|
|
|
|
|
|
2013-07-29 13:27:17 +02:00
|
|
|
Note that a single colon `:` follows a configuration axis and a double
|
|
|
|
|
colon `::` follows a task axis.
|
2012-09-15 00:08:35 +02:00
|
|
|
|
|
|
|
|
Discovering Settings and Tasks
|
|
|
|
|
==============================
|
|
|
|
|
|
2013-07-29 13:27:17 +02:00
|
|
|
This section discusses the `inspect` command, which is useful for
|
2012-09-15 00:08:35 +02:00
|
|
|
exploring relationships between settings. It can be used to determine
|
|
|
|
|
which setting should be modified in order to affect another setting, for
|
|
|
|
|
example.
|
|
|
|
|
|
|
|
|
|
Value and Provided By
|
|
|
|
|
---------------------
|
|
|
|
|
|
2013-07-29 13:27:17 +02:00
|
|
|
The first piece of information provided by `inspect` is the type of a
|
2012-09-15 00:08:35 +02:00
|
|
|
task or the value and type of a setting. The following section of output
|
|
|
|
|
is labeled "Provided by". This shows the actual scope where the setting
|
|
|
|
|
is defined. For example,
|
|
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2012-11-19 02:29:01 +01:00
|
|
|
> inspect libraryDependencies
|
2012-09-15 00:08:35 +02:00
|
|
|
[info] Setting: scala.collection.Seq[sbt.ModuleID] = List(org.scalaz:scalaz-core:6.0-SNAPSHOT, org.scala-tools.testing:scalacheck:1.8:test)
|
|
|
|
|
[info] Provided by:
|
2012-11-19 02:29:01 +01:00
|
|
|
[info] {file:/home/user/sample/}root/*:libraryDependencies
|
2012-09-15 00:08:35 +02:00
|
|
|
...
|
|
|
|
|
|
2013-09-27 00:26:19 +02:00
|
|
|
This shows that :key:`libraryDependencies` has been defined on the current
|
2013-07-29 13:27:17 +02:00
|
|
|
project (`{file:/home/user/sample/}root`) in the global configuration
|
2013-09-27 00:26:19 +02:00
|
|
|
(`*:`). For a task like :key:`update`, the output looks like:
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
|
|
|
|
> inspect update
|
|
|
|
|
[info] Task: sbt.UpdateReport
|
|
|
|
|
[info] Provided by:
|
|
|
|
|
[info] {file:/home/user/sample/}root/*:update
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
Related Settings
|
|
|
|
|
----------------
|
|
|
|
|
|
2013-07-29 13:27:17 +02:00
|
|
|
The "Related" section of `inspect` output lists all of the definitions
|
2012-09-15 00:08:35 +02:00
|
|
|
of a key. For example,
|
|
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
|
|
|
|
> inspect compile
|
|
|
|
|
...
|
|
|
|
|
[info] Related:
|
|
|
|
|
[info] test:compile
|
|
|
|
|
|
2013-07-29 13:27:17 +02:00
|
|
|
This shows that in addition to the requested `compile:compile` task,
|
|
|
|
|
there is also a `test:compile` task.
|
2012-09-15 00:08:35 +02:00
|
|
|
|
|
|
|
|
Dependencies
|
|
|
|
|
------------
|
|
|
|
|
|
|
|
|
|
Forward dependencies show the other settings (or tasks) used to define a
|
|
|
|
|
setting (or task). Reverse dependencies go the other direction, showing
|
2013-07-29 13:27:17 +02:00
|
|
|
what uses a given setting. `inspect` provides this information based
|
2012-09-15 00:08:35 +02:00
|
|
|
on either the requested dependencies or the actual dependencies.
|
|
|
|
|
Requested dependencies are those that a setting directly specifies.
|
|
|
|
|
Actual settings are what those dependencies get resolved to. This
|
|
|
|
|
distinction is explained in more detail in the following sections.
|
|
|
|
|
|
|
|
|
|
Requested Dependencies
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
2013-09-27 00:26:19 +02:00
|
|
|
As an example, we'll look at :key:`console`:
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
|
|
|
|
> inspect console
|
|
|
|
|
...
|
|
|
|
|
[info] Dependencies:
|
2012-11-19 02:29:01 +01:00
|
|
|
[info] compile:console::fullClasspath
|
|
|
|
|
[info] compile:console::scalacOptions
|
|
|
|
|
[info] compile:console::initialCommands
|
|
|
|
|
[info] compile:console::cleanupCommands
|
2012-09-15 00:08:35 +02:00
|
|
|
[info] compile:console::compilers
|
2012-11-19 02:29:01 +01:00
|
|
|
[info] compile:console::taskTemporary-directory
|
|
|
|
|
[info] compile:console::scalaInstance
|
2012-09-15 00:08:35 +02:00
|
|
|
[info] compile:console::streams
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
2013-09-27 00:26:19 +02:00
|
|
|
This shows the inputs to the :key:`console` task. We can see that it gets
|
|
|
|
|
its classpath and options from :key:`fullClasspath` and
|
2013-07-29 13:27:17 +02:00
|
|
|
`scalacOptions(for console)`. The information provided by the
|
|
|
|
|
`inspect` command can thus assist in finding the right setting to
|
2013-09-27 00:26:19 +02:00
|
|
|
change. The convention for keys, like :key:`console` and
|
|
|
|
|
:key:`fullClasspath`, is that the Scala identifier is camel case, while
|
2012-09-15 00:08:35 +02:00
|
|
|
the String representation is lowercase and separated by dashes. The
|
|
|
|
|
Scala identifier for a configuration is uppercase to distinguish it from
|
2013-09-27 00:26:19 +02:00
|
|
|
tasks like :key:`compile` and :key:`test`. For example, we can infer from the
|
2012-09-15 00:08:35 +02:00
|
|
|
previous example how to add code to be run when the Scala interpreter
|
|
|
|
|
starts up:
|
|
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
|
|
|
|
> set initialCommands in Compile in console := "import mypackage._"
|
|
|
|
|
> console
|
|
|
|
|
...
|
|
|
|
|
import mypackage._
|
|
|
|
|
...
|
|
|
|
|
|
2013-09-27 00:26:19 +02:00
|
|
|
`inspect` showed that :key:`console` used the setting
|
2013-07-29 13:27:17 +02:00
|
|
|
`compile:console::initialCommands`. Translating the
|
2013-09-27 00:26:19 +02:00
|
|
|
:key:`initialCommands` string to the Scala identifier gives us
|
|
|
|
|
:key:`initialCommands`. :key:`compile` indicates that this is for the main
|
2013-07-29 13:27:17 +02:00
|
|
|
sources. `console::` indicates that the setting is specific to
|
2013-09-27 00:26:19 +02:00
|
|
|
:key:`console`. Because of this, we can set the initial commands on the
|
|
|
|
|
:key:`console` task without affecting the :key:`consoleQuick` task, for
|
2012-09-15 00:08:35 +02:00
|
|
|
example.
|
|
|
|
|
|
|
|
|
|
Actual Dependencies
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
2013-07-29 13:27:17 +02:00
|
|
|
`inspect actual <scoped-key>` shows the actual dependency used. This
|
2012-09-15 00:08:35 +02:00
|
|
|
is useful because delegation means that the dependency can come from a
|
2013-07-29 13:27:17 +02:00
|
|
|
scope other than the requested one. Using `inspect actual`, we see
|
2012-09-15 00:08:35 +02:00
|
|
|
exactly which scope is providing a value for a setting. Combining
|
2013-07-29 13:27:17 +02:00
|
|
|
`inspect actual` with plain `inspect`, we can see the range of
|
2012-09-15 00:08:35 +02:00
|
|
|
scopes that will affect a setting. Returning to the example in Requested
|
|
|
|
|
Dependencies,
|
|
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
|
|
|
|
> inspect actual console
|
|
|
|
|
...
|
|
|
|
|
[info] Dependencies:
|
2012-11-19 02:29:01 +01:00
|
|
|
[info] compile:scalacOptions
|
|
|
|
|
[info] compile:fullClasspath
|
|
|
|
|
[info] *:scalaInstance
|
|
|
|
|
[info] */*:initialCommands
|
|
|
|
|
[info] */*:cleanupCommands
|
|
|
|
|
[info] */*:taskTemporaryDirectory
|
2012-09-15 00:08:35 +02:00
|
|
|
[info] *:console::compilers
|
|
|
|
|
[info] compile:console::streams
|
|
|
|
|
...
|
|
|
|
|
|
2013-07-29 13:27:17 +02:00
|
|
|
For `initialCommands`, we see that it comes from the global scope
|
|
|
|
|
(`*/*:`). Combining this with the relevant output from
|
|
|
|
|
`inspect console`:
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2012-11-19 02:29:01 +01:00
|
|
|
compile:console::initialCommands
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2013-09-27 00:26:19 +02:00
|
|
|
we know that we can set :key:`initialCommands` as generally as the global
|
|
|
|
|
scope, as specific as the current project's :key:`console` task scope, or
|
2012-09-15 00:08:35 +02:00
|
|
|
anything in between. This means that we can, for example, set
|
2013-09-27 00:26:19 +02:00
|
|
|
:key:`initialCommands` for the whole project and will affect :key:`console`:
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
|
|
|
|
> set initialCommands := "import mypackage._"
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
The reason we might want to set it here this is that other console tasks
|
|
|
|
|
will use this value now. We can see which ones use our new setting by
|
2013-07-29 13:27:17 +02:00
|
|
|
looking at the reverse dependencies output of `inspect actual`:
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2012-11-19 02:29:01 +01:00
|
|
|
> inspect actual initialCommands
|
2012-09-15 00:08:35 +02:00
|
|
|
...
|
|
|
|
|
[info] Reverse dependencies:
|
|
|
|
|
[info] test:console
|
2012-11-19 02:29:01 +01:00
|
|
|
[info] compile:consoleQuick
|
2012-09-15 00:08:35 +02:00
|
|
|
[info] compile:console
|
2012-11-19 02:29:01 +01:00
|
|
|
[info] test:consoleQuick
|
|
|
|
|
[info] *:consoleProject
|
2012-09-15 00:08:35 +02:00
|
|
|
...
|
|
|
|
|
|
2013-09-27 00:26:19 +02:00
|
|
|
We now know that by setting :key:`initialCommands` on the whole project,
|
2012-09-15 00:08:35 +02:00
|
|
|
we affect all console tasks in all configurations in that project. If we
|
2013-09-27 00:26:19 +02:00
|
|
|
didn't want the initial commands to apply for :key:`consoleProject`, which
|
2012-09-15 00:08:35 +02:00
|
|
|
doesn't have our project's classpath available, we could use the more
|
|
|
|
|
specific task axis:
|
|
|
|
|
|
2013-07-29 13:27:17 +02:00
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
> set initialCommands in console := "import mypackage._"
|
|
|
|
|
> set initialCommands in consoleQuick := "import mypackage._"`
|
|
|
|
|
|
2012-09-15 00:08:35 +02:00
|
|
|
or configuration axis:
|
|
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
|
|
|
|
> set initialCommands in Compile := "import mypackage._"
|
|
|
|
|
> set initialCommands in Test := "import mypackage._"
|
|
|
|
|
|
|
|
|
|
The next part describes the Delegates section, which shows the chain of
|
|
|
|
|
delegation for scopes.
|
|
|
|
|
|
|
|
|
|
Delegates
|
|
|
|
|
---------
|
|
|
|
|
|
|
|
|
|
A setting has a key and a scope. A request for a key in a scope A may be
|
|
|
|
|
delegated to another scope if A doesn't define a value for the key. The
|
|
|
|
|
delegation chain is well-defined and is displayed in the Delegates
|
2013-07-29 13:27:17 +02:00
|
|
|
section of the `inspect` command. The Delegates section shows the
|
2012-09-15 00:08:35 +02:00
|
|
|
order in which scopes are searched when a value is not defined for the
|
|
|
|
|
requested key.
|
|
|
|
|
|
2013-09-27 00:26:19 +02:00
|
|
|
As an example, consider the initial commands for :key:`console` again:
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2012-09-19 02:12:32 +02:00
|
|
|
.. code-block:: console
|
2012-09-15 00:08:35 +02:00
|
|
|
|
2012-11-19 02:29:01 +01:00
|
|
|
> inspect console::initialCommands
|
2012-09-15 00:08:35 +02:00
|
|
|
...
|
|
|
|
|
[info] Delegates:
|
2012-11-19 02:29:01 +01:00
|
|
|
[info] *:console::initialCommands
|
|
|
|
|
[info] *:initialCommands
|
|
|
|
|
[info] {.}/*:console::initialCommands
|
|
|
|
|
[info] {.}/*:initialCommands
|
|
|
|
|
[info] */*:console::initialCommands
|
|
|
|
|
[info] */*:initialCommands
|
2012-09-15 00:08:35 +02:00
|
|
|
...
|
|
|
|
|
|
|
|
|
|
This means that if there is no value specifically for
|
2013-07-29 13:27:17 +02:00
|
|
|
`*:console::initialCommands`, the scopes listed under Delegates will
|
2012-09-15 00:08:35 +02:00
|
|
|
be searched in order until a defined value is found.
|