Building a Dart Project
What This Guide Covers #
This guide covers build environment and configuration topics specific to Dart projects. Please make sure to read our Onboarding and General Build configuration guides first.
Community-Supported Warning #
Travis CI support for Dart is contributed by the community and may be removed or altered at any time. If you run into any problems, please report them in the Travis CI issue tracker and cc @athomas and @a14n.
Choosing Dart versions to test against #
Dart workers on Travis CI download and install the Dart SDK archives. See
the Dart Download Archive for the list of
available archives. By default, the latest stable SDK version is downloaded. To
explicitly select one or more versions, use the dart
key. For example:
language: dart
dart:
# Install the latest stable release
- stable
# Install the latest beta release
- beta
# Install the latest dev release
- dev
# Install a specific stable release - 1.15.0
- "1.15.0"
# Install a specific dev release, using a partial download URL - 2.9.0-2.0.dev
- "dev/release/2.9.0-2.0.dev"
# Install a specific beta release, using a partial download URL - 2.9.0-2.0.beta
- "beta/release/2.9.0-2.0.beta"
Running Tests #
If your package depends on the test
package, pub run test
will be
run by default. This typically only runs tests on the Dart VM, but you can
configure it to run on additional platforms by default.
You can also customize the arguments Travis passes to the test runner using the
dart_task
field in .travis.yml
.
language: dart
dart_task:
- test: --platform vm
- test: --platform chrome
Available Browsers #
Travis comes with Firefox and Chrome installed by default on Linux, and Safari
on macOS. However, if you want to run your tests on Dartium, you’ll need to
install it by adding install_dartium: true
either at the top level or for a
particular task.
language: dart
dart_task:
- test: --platform vm
- test: --platform dartium
install_dartium: true
XVFB #
On Linux, the test runner uses XVFB by default so that it can use browsers
like Chrome that require a display. However, this may interfere with certain
applications, so you can turn it off by setting xvfb: false
either at the top
level or for a particular task.
language: dart
dart_task:
- test: --exclude-tags no-xvfb
- test: --tags no-xvfb
xvfb: false
XVFB is never used on macOS, since it doesn’t use the X windows system.
Other Tasks #
Several tasks are available in addition to running tests.
Analyzer #
To run the Dart analyzer to verify that your code doesn’t have any static
errors, add a task with dartanalyzer: true
. By default it analyzes all Dart
files in your repository, but you can configure it by providing arguments
instead of true
.
language: dart
dart_task:
# As long as you don't want any other configuration, you can just use the name
# of a task instead of "name: true".
- test
# Warnings are fatal, but we only analyze the lib/ directory.
- dartanalyzer: --fatal-warnings lib
Formatter #
To run the Dart formatter to verify that all your files are correctly
formatted, add a task with dartfmt: true
. If your package depends on the
dart_style
package, it’ll use that package’s formatter version; otherwise,
it’ll use the dartfmt
that comes with your Dart SDK.
language: dart
dart_task:
- test: --platform vm
- test: --platform chrome
- dartfmt
Environment Variables #
- The version of Dart a job is using is available as
TRAVIS_DART_VERSION
. TRAVIS_DART_TEST
will betrue
if the current task usestest
.TRAVIS_DART_ANALYZE
will betrue
if the current task usesdartanalyzer
.TRAVIS_DART_FORMAT
will betrue
if the current task usesdartfmt
.
Build Config Reference #
You can find more information on the build config format for Dart in our Travis CI Build Config Reference.