Dart Repository

Cloudsmith provides public & private repositories for Dart packages

835835

Dart is a client-optimized programming language developed by Google.

For more information on Dart, please see:

  • Dart.dev: The official website for Dart
  • Pub.dev: The official public repository for Dart packages
Contextual Documentation

The examples in this document are generic. Cloudsmith provides contextual setup instructions within each repository, complete with copy n' paste snippets (with your namespace/repo pre-configured).

In the following examples:

Identifier

Description

OWNER

Your Cloudsmith account name or organisation name (namespace)

REPOSITORY

Your Cloudsmith Repository name (also called "slug")

TOKEN

Your Cloudsmith Entitlement Token (see Entitlements for more details)

USERNAME

Your Cloudsmith username

PASSWORD

Your Cloudsmith password

API-KEY

Your Cloudsmith API Key

PACKAGE_NAME

The name of your package

PACKAGE_VERSION

The version number of your package

DEPENDENCY_NAME

A name for a dependency in a pubspec file

Upload a Package

Publish via Dart

📘

Please note that Dart SDK version 2.15.1 or newer is required for native upload support. For older client versions, please continue to use the Cloudsmith CLI/API.

The endpoint for the native Dart API is:

https://dart.cloudsmith.io/OWNER/REPOSITORY/

Your project pubspec.yaml defines the location that artifacts should be published to. Add the following to the root of this file:

publish_to: https://dart.cloudsmith.io/OWNER/REPOSITORY/

In order to authenticate for native publishing, you'll need run dart pub token, as follows:

echo 'API-KEY' | dart pub token add https://dart.cloudsmith.io/OWNER/REPOSITORY/
Enter secret token:
Requests to "https://dart.cloudsmith.io/OWNER/REPOSITORY/" will now be authenticated using the secret token.

You can then publish from your project directory using dart pub publish:

dart pub publish
Uploading...
Upload complete. Package will available following synchronisation.

📘

Limitation:

When publishing via the native API package sizes are limited to 200.0 MB per file. If this is an issue, please use the Cloudsmith CLI or API (which support up to 5GB for single-part uploads and beyond for multi-part), or contact us if that's not an option.

Upload via the Cloudsmith CLI

📘

Please see Dart's documentation on creating packages for more information on building your own packages.

Creating Dart Packages

To upload via the Cloudsmith API/CLI, you'll need to generate a package first. While we expect the tooling in this area to improve over time, currently the process is a manual one and can be a little tricky.

You can build a package with standard command-line tooling like tar. To illustrate the process we'll use cli_util as an example:

First, check out the version of cli_util we want to pack (v0.1.3 for example purposes):

git clone https://github.com/dart-lang/[email protected]
cd cli_util
tar --exclude='.dart_tool' -czvf cli_util_0.1.3.tar.gz ./*

For full details of how to install and setup the Cloudsmith CLI, see Command Line Interface.

The command to upload a Dart package via the Cloudsmith CLI is:

cloudsmith push dart OWNER/REPOSITORY PACKAGE_NAME-PACKAGE_VERSION.tgz

Example:

cloudsmith push dart org/repo your-package-1.0.0.tgz

Upload via Cloudsmith Website

Please see Upload a Package for details of how to upload via the Website UI.


Download / Install a Package

Instaling packages from this repository varies, depending on the version of the Dart SDK in use.

Setup

SDK Version >= 2.15

Public Repositories

No further setup is required when using Dart SDK >= 2.15 with public repositories, you can add a dependency from this repository to your package pubspec.yaml automatically with dart pub. See Installing a Package

Private Repositories

In order to authenticate, you need to run dart pub token, as follows:

echo 'TOKEN' | dart pub token add https://dart.cloudsmith.io/OWNER/REPOSITORY/
Enter secret token:
Requests to "https://dart.cloudsmith.io/OWNER/REPOSITORY/" will now be authenticated using the secret token.
echo 'PASSWORD' | dart pub token add https://dart.cloudsmith.io/OWNER/REPOSITORY/
Enter secret token:
Requests to "https://dart.cloudsmith.io/OWNER/REPOSITORY/" will now be authenticated using the secret token.
echo 'API-KEY' | dart pub token add https://dart.cloudsmith.io/OWNER/REPOSITORY/
Enter secret token:
Requests to "https://dart.cloudsmith.io/OWNER/REPOSITORY/" will now be authenticated using the secret token.
echo 'TOKEN' | dart pub token add https://dart.cloudsmith.io/OWNER/REPOSITORY/
Enter secret token:
Requests to "https://dart.cloudsmith.io/OWNER/REPOSITORY/" will now be authenticated using the secret token.

SDK Version <= 2.14

Before you can install packages from your Cloudsmith repository you'll need to configure your environment for access. The configuration is defined using the PUB_HOSTED_URL environment variable.

🚧

Note

This approach is not recommended, and we strongly encourage the use of the method detailed for SDK 2.15 onwards. This approach has the effect of embedding access tokens within your generated pubspec.lock file. As these typically tend to get committed to source repositories, this is a potential attack vector.

🚧

When using PUB_HOSTED_URL, all dependencies must be present in the specified Cloudsmith repository. Dart repositories don't (currently) proxy upstream sources and can only serve packages explicitly uploaded to Cloudsmith. So if set, you cannot resolve any dependencies from pub.dev.

If PUB_HOSTED_URL is unset, any packages not uploaded to Cloudsmith (and with a specific Cloudsmith URL set in the pubspec.yaml file) will be fetched from pub.dev

Public Repositories

Linux / Mac

export PUB_HOSTED_URL=https://dl.cloudsmith.io/public/OWNER/REPOSITORY/dart/

Windows (cmd)

set PUB_HOSTED_URL=https://dl.cloudsmith.io/public/OWNER/REPOSITORY/dart/

Windows (Powershell)

$env:PUB_HOSTED_URL=https://dl.cloudsmith.io/public/OWNER/REPOSITORY/dart/

Private Repositories

📘

Private Cloudsmith repositories require authentication. You can choose between two types of authentication, Entitlement Token Authentication or HTTP Basic Authentication.

The setup method will differ depending on what authentication type you choose to use.

Linux / Mac

export PUB_HOSTED_URL=https://dl.cloudsmith.io/TOKEN/OWNER/REPOSITORY/dart/
export PUB_HOSTED_URL=https://USERNAME:[email protected]/basic/OWNER/REPOSITORY/dart/
export PUB_HOSTED_URL=https://USERNAME:[email protected]/basic/OWNER/REPOSITORY/dart/
export PUB_HOSTED_URL=https://token:[email protected]/basic/OWNER/REPOSITORY/dart/

Windows (cmd)

set PUB_HOSTED_URL=https://dl.cloudsmith.io/TOKEN/OWNER/REPOSITORY/dart/
set PUB_HOSTED_URL=https://USERNAME:[email protected]/basic/OWNER/REPOSITORY/dart/
set PUB_HOSTED_URL=https://USERNAME:[email protected]/basic/OWNER/REPOSITORY/dart/
set PUB_HOSTED_URL=https://token:[email protected]/basic/OWNER/REPOSITORY/dart/

Windows (Powershell)

$env:PUB_HOSTED_URL=https://dl.cloudsmith.io/TOKEN/OWNER/REPOSITORY/dart/
$env:PUB_HOSTED_URL=https://USERNAME:[email protected]/basic/OWNER/REPOSITORY/dart/
$env:PUB_HOSTED_URL=https://USERNAME:[email protected]/basic/OWNER/REPOSITORY/dart/
$env:PUB_HOSTED_URL=https://token:[email protected]/basic/OWNER/REPOSITORY/dart/

Installing a Package

SDK Version >= 2.15

dart pub is capable of adding a dependency from this repository to your package pubspec.yaml automatically:

Public Or Private Repositories

dart pub add PACKAGE_NAME:PACKAGE_VERSION --hosted-url https://dart.cloudsmith.io/OWNER/REPOSITORY/
Resolving dependencies...
+ your-package 1.2.3
Downloading your-package 1.2.3...
Changed 1 dependency!

SDK Version <= 2.14

Public Repositories

A dependency may be manually added to your project pubspec.yaml file:

dependencies:
 DEPENDENCY_NAME:
    hosted:
      name: PACKAGE_NAME
      url: https://dl.cloudsmith.io/public/OWNER/REPOSITORY/dart/
      version: PACKAGE_VERSION

Private Repositories

dependencies:
  your-package:
    version: PACKAGE_VERSION

Once set up, pub will download the dependency to .pub_cache and update the pubspec.lock and .packages after running following command:

pub get

Please also see the pubspec docs for further examples of pubspec files.

Upstream Proxying / Caching

Configurable Proxying
You can configure upstream Dart repositories that you wish to use for packages that are not available in your Cloudsmith repository. Proxied Dart packages cannot currently be cached.

Please see our Upstream Proxying documentation for further instructions.

Key Signing Support

Not Supported by Format

Troubleshooting

Please see the Troubleshooting page for further help and information.


Did this page help you?

Cloudsmith is the new standard in Package / Artifact Management and Software Distribution

With support for all major package formats, you can trust us to manage your software supply chain.


Start My Free Trial Now
Cookie Declaration (Manage Cookies)