The promise of Cloudsmith is simple. We ensure development teams have access to the packages they need, when they need them.

And we do that through a private, cloud-based repository that can help shield the business from malware, security and licensing concerns related to the use of third party software packages, whilst giving you total control over access to your own packages.

A key aspect of our approach is universality. We understand that individual developers and teams work in multiple languages and with multiple package formats. We allow them to continue to do just that, but handle package management in a consistent, reliable and performant way through Cloudsmith.

Today, as part of that commitment, we’re launching support for private Dart package repositories.

The Dart Ecosystem

Dart is an open-source, object-oriented, general-purpose programming language developed by Google. It is a client-optimized language for building fast apps on any platform, focused on providing a productive environment for developers new to the web, especially developers comfortable with structured languages and tools.

Since 2013, Google has implemented websites such as AdWords and Google Fiber using Dart, and in 2017, we saw the release of Flutter; Google’s UI framework for building native interfaces in iOS and Android, which is built on top of Dart.

The popularity of Flutter has spurred a revival of Dart's usage for mobile development, a process accelerated by the roll-out of Dart 2.0, which featured improvements to client-side development, including strong typing and “UI as code”. Dart also appears to be popular with those who use it. In 2019 the Stack Overflow developer survey found that 66.3% of those using Dart would continue to use it in future - putting it firmly in the ‘loved’ category.  

Dart comes bundled with Pub, a package manager for the Dart programming language, containing reusable libraries & packages for Flutter and general Dart programs.

As most readers will know, packages allow code-sharing and reusability across Flutter/Dart apps. Pub is responsible for downloading and installing these packages, mostly from pub.dev, the official Dart package repository.

But you don’t have to use pub.dev. Pub provides all the necessary tooling and configuration flags to point at another repository if needed.

And there are several great reasons you may wish to do exactly that - and run your own private repository on Cloudsmith. Taking this approach allows development teams to:

  • Develop Dart packages internally and share them privately to other teams.
  • Distribute and deploy your own Dart packages in a pipeline at your org.
  • Distribute Dart packages as commercial  software.
  • Make modifications to public Dart packages, without republishing publicly.
  • Mirror public Dart packages and isolate from uncontrolled upstream issues.
  • Capture the exact state of your dependencies at a particular version/release.
  • Control (whitelist/blacklist) the exact Dart packages allowed for your org.
  • Keep track of the exact versions/releases of Dart packages you have/use.

In short: deliver all the benefits of Cloudsmith that are already enjoyed by development teams all over the world today.

If you want to join them, sign up today to begin hosting and distributing your Dart packages at the world's first hosted private Dart package repository service.

See also:

Getting Started

Getting started with Cloudsmith and Dart couldn't be simpler.

First, you'll need a Cloudsmith account and a repository to which you can upload packages. Secondly, you'll need to ensure you're running at least version 2.0 (or later) of Dart.

You can check your currently installed Dart and Pub versions like so:

$ dart --version
Dart VM version: 2.7.0 (Fri Dec 6 16:26:51 2019 +0100) on "macos_x64"
$ pub --version
Pub 2.7.0

If you see something like the above, you're ready to go!

Creating your Dart package

For the purposes of this demonstration, we will create a dart file containing a single function that prints a message, and a pubspec file used to create a package.

The output.dart file should be located within a lib folder and contain:

void greet(){
    print('Cloudsmith: Be Awesome. Automate Everything.');
}

The contents of the pubspec.yaml file should contain:

name: "my-package"
description: "Simple package wth a simple message"
version: "0.1.0"
homepage: "your_homepage"
documentation: "your_docs"
author: "You <you@domain.com>"
environment:
    sdk: '>=2.0.0 <3.0.0'

If you take a look inside the new directory where you created these files you'll see the following:

├── lib
│   ├── output.dart
└── pubspec.yaml

At present, the native tooling does not support generating a package but it can be used to validate the pubspec.yaml using the lish command via pub:

$ pub lish

To create the package, we will use tar to copy all files into a .tar.gz. In this example, the only files that exist are our pubspec and dart file however it's important to exclude any unnecessary files.

$ tar --exclude='.dart_tool' -czf my-package-0.1.0.tar.gz ./*

Once built you can push the package to Cloudsmith using the Cloudsmith CLI. We don't yet support pushing packages with pub publish, but we'll be adding support in a future release (if you want it, please let us know). For now, use the CLI.

Publishing your Dart packages to Cloudsmith

First, ensure you've installed the Cloudsmith CLI and configured authentication:

$ pip install cloudsmith-cli
$ export CLOUDSMITH_API_KEY=xxxxx

Then, use the CLI to push the package, which operates like pub publish but is specific to Cloudsmith:

$ cloudsmith push dart my-org/my-repo my-package-0.1.0.tar.gz

Checking dart package upload parameters ... OK
Checking my-package-0.1.0.tar.gz file upload parameters ... OK

Requesting file upload for my-package-0.1.0.tar.gz ... OK

Creating a new dart package ... OK
Created: my-org/my-repo/my-package-010targz (eeb4n20QxSYM)

Synchronising my-package-010targz:  [####################################]  100%  Sync Completed / Fully Synchronised

Package synchronised successfully!

Your repository should now contain the uploaded package. An example of which is our official Cloudsmith examples repository (this is where we upload our examples from), as shown below:

Installing your Dart packages from Cloudsmith

First, we need to tell Pub how to access the repository. To do so you need to add the following entry in your pubspec.yml (replace TOKEN with an entitlement token, which is a type of read-only authentication token that we support)

Add this to your package's pubspec.yaml file:

dependencies:
  cloudsmith_dart_example:
	hosted:
	  name: cloudsmith_dart_example
	  url: https://dl.cloudsmith.io/TOKEN/my-org/my-repo/dart/
	version: ^1.0.0

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Now in your Dart code, you can use:

import 'package:my_package/output.dart';

It really is that simple, and now you've sourced a Dart package privately from your very own private Dart repository on Cloudsmith. Well done!

Conclusion

Cloudsmith provides fully featured Dart repositories on all plans, flexible enough for use whether you’re hosting public packages for a public or open-source project, or private packages for your company’s internal needs. We're extremely proud to be able to support the Dart ecosystem with this first (non-official) implementation of public and private Dart packages.

You can find further, context-specific information, including detailed setup and integration instructions inside each Cloudsmith repository. You can see an example of this documentation in our public examples repository.

Why wait? Get your public and private Dart repository hosting at Cloudsmith now.