Skip to main content

dart-quickstart

Last updated on

Prerequisites

  • Ensure you have the Dart CLI dart and Flutter CLI flutter installed on your local machine.
  • Access to a Harness account with appropriate permissions to create registries and connectors.

Create a Dart artifact registry

private registry

This registry will serve as your private Dart registry within Harness.


Configure an Upstream Proxy (Optional)

An upstream proxy allows your registry to fetch NuGet packages from external sources if they are not available locally.

Create an upstream proxy

Configure the upstream proxy in your registry

upstream proxy caching

If a Dart package isn't found in your Harness registry, the upstream proxy automatically fetches it from an external source like pub.dev. The package is then cached in your registry, ensuring faster downloads for subsequent requests.


Install and Use Dart Packages

Configure Authentication

Step 1

Add authentication token to Dart pub:

dart pub token add https://pkg.harness.io/pkg/<account-id>/<dart-registry-name>/pub/
Step 2

Enter your <TOKEN> when prompted.

info

Replace <account-id> with your Harness account ID and <dart-registry-name> with your registry name.

Install a Dart Package

Step 1

In your consuming project's pubspec.yaml, add the dependency pointing to the hosted URL:

dependencies:
<ARTIFACT_NAME>:
hosted:
name: <ARTIFACT_NAME>
url: https://pkg.harness.io/pkg/<account-id>/<dart-registry-name>/pub/
version: <VERSION>
Step 2

Then fetch it:

dart pub get

Publish a Dart Package

Step 1

In your package's pubspec.yaml, set the registry URL:

publish_to: https://pkg.harness.io/pkg/<account-id>/<dart-registry-name>/pub/
name: <ARTIFACT_NAME>
version: <VERSION>
description: My first Dart package
environment:
sdk: ">=3.0.0 <4.0.0"
Step 2

Then run:

dart pub publish