Cloudsmith + Dart = The World's First Private Dart Repository Service
Tags: cloudsmith, dart, flutter, devops
Published: 2020-03-25 19:24:41

---
title: Cloudsmith + Dart = The World's First Private Dart Repository Service
published: true
description: Cloudsmith launches the World's First Private Dart Repository Service.
tags: cloudsmith, dart, flutter, devops
canonical_url: https://blog.cloudsmith.io/2020/02/03/worlds-first-private-dart-repository-service-w-cloudsmith/
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/xzr1k6w79up06s2exwrr.jpg
series: Cloudsmith Universal Format Support
---

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.

{% youtube cpW4fK_y4zU %}

#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](https://insights.stackoverflow.com/survey/2019#most-loved-dreaded-and-wanted) 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](https://pub.dev/).

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](https://cloudsmith.io/user/signup/) to begin hosting and distributing your Dart packages at the world's first hosted private Dart package repository service.

See also:
- Dart: https://www.dart.dev/
- Pub: https://pub.dev


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

First, you'll need a [Cloudsmith account](https://cloudsmith.io/user/signup/) 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](https://pypi.org/project/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](https://github.com/cloudsmith-io/cloudsmith-examples) from), as shown below:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/n3vfgebg7z7oi935wby4.png)

## 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.yaml_ (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](https://cloudsmith.io/user/signup/).