Improvements to Dart Package Support

Feb 2 2022/Software Package Formats/4 min read
Cloudsmith improves Dart package support
For Dart 2.15, Cloudsmith worked with the Google Dart team to advance existing support for Dart Packages, allowing authentication for private Dart repositories.

At Cloudsmith, our core mission is to be THE universal package repository. That is why we support so many different packages, artifacts, and image formats and constantly improve the functionality and support we provide.

With this in mind, we are happy to announce the latest improvements to our support for Dart packages.

The History of Cloudsmith and Dart

In 2020, what seems like a lifetime ago, Cloudsmith was the first package management product to announce support for Dart packages in private repositories. We have always been big fans of Dart and what the Google Dart team has been trying to achieve.

Before the Dart SDK 2.15 release, the Dart client tooling didn't have native support for authenticating private repositories, nor any native support for publishing dart packages to private repositories.

Cloudsmith did support the ability to push Dart packages to a private repository via the Cloudsmith CLI  `cloudsmith push dart`  command, as we do for all the package formats we support. However, we prefer supporting native package tooling where possible, and we always recommend using native tooling to publish packages.

Adding Advanced Support for Dart Packages

Since 2020, we have had many customers use our Dart support, and, as with all the features we add to Cloudsmith, we have listened to their feedback and used this to drive our product development and roadmap. So we were delighted when the opportunity came up to work alongside the Google Dart team. Together, we’ve added advanced support for some of the awesome improvements that landed as part of the Dart 2.15 release, as it was clear that they too have been listening to the broader Dart community.

Improvements, you say? Tell me more!

From the Cloudsmith perspective, arguably, the most significant improvement that the Dart team worked on was adding support for authentication for 3rd party repositories.  This support allows authenticating via the native Dart tooling to repositories such as Cloudsmith and it greatly expands the possible places to securely host your Dart packages beyond (the official public source for Dart packages). It opens the door to more accessible use of private repositories.

This support took the form of the dart pub token command. This command allows storing and managing secret tokens for authenticating against third-party repositories, publishing packages, and retrieving dependencies.

This means that you can use the dart pub token command with your Cloudsmith API Key to configure the Dart client to publish packages directly to your private repositories on Cloudsmith. And you can also use it with a Cloudsmith Entitlement Token if you’d like to provide secure, read-only access to pull packages/dependencies from a private Cloudsmith repository.

This change has made integrating private repositories on Cloudsmith so much tighter, more secure, more straightforward, and, dare I say it, “Just Better”!

While the older method of using the Cloudsmith CLI and the cloudsmith push dart command is still supported for anyone using Dart 2.14 or earlier, with Dart 2.15.1, it’s now so much easier to store your credentials securely. You also have one less thing to install as part of your CI environment or build pipeline.

Don’t get me wrong, we LOVE the Cloudsmith CLI, and it has all sorts of handy functionality for interacting with and managing your resources on Cloudsmith. But when it comes to the core acts of working with packages, publishing/pushing and pulling/installing, there is no doubt that using the native tooling for whatever package formats you use is the right way to go.

Let’s look at an example.

Publishing a Package to Cloudsmith

The new Cloudsmith endpoint for the native Dart API is:{ACCOUNT}/{REPO}

(Where {ACCOUNT} is your Cloudsmith Organization identifier/namespace and {REPO} is your Cloudsmith Repo name/identifier)

So, to specify the location that you wish to publish a Dart project to, you just need to add the following to the root of your pubspec.yaml file:


Then, to store your Cloudsmith API Key to authenticate for publishing, you just need to use the dart pub token add command:

echo '{YOUR-API-KEY}' | dart pub token add{ACCOUNT}/{REPO}/

You can then simply publish your Dart package from your project directory with dart pub publish as follows:

dart pub publish

It’s that simple!

Installing a Package from Cloudsmith

It’s also just as straightforward to install a package. While you absolutely can use your Cloudsmith API key to authenticate (as you would when publishing) and pull a package, you can also use a Cloudsmith Entitlement Token:

echo '{TOKEN}' | dart pub token add{ACCOUNT}/{REPO}/

And then dart pub can add a dependency from this repository to your package pubspec.yaml automatically:

dart pub add your-package:1.2.3 --hosted-url

Again, it really is that simple.

For those who’d prefer to watch, see our video tutorial on setting up a private Dart repository using Cloudsmith, or read our official documentation on how to push dart packages to Cloudsmith.

To Sum Up

The release of Dart 2.15.1 and the associated improvements to Cloudsmith to support the new functionality this release provides to ensure that Dart packages remain first-class citizens on Cloudsmith. Our customers are very excited to see this progress.

We will continue to push forward, both with support for new package types and keeping our support for existing package types as current as possible. We know that private Cloudsmith repositories sit right at the heart of our customers' build and deployment pipelines and this is not a responsibility that we take lightly. Our customers rely on us, and we are dedicated to providing a best-in-class package management service.

As always, we would love to hear from you about these improvements or anything package management related!

Likewise, we get that you might just want to jump right in and try it out for yourself. Start building a private Dart repository today with a free 14-day trial - no credit card needed.

Happy packaging!

Get our next blog straight to your inbox