dart-quickstart
Prerequisites
- Ensure you have the Dart CLI
dartand Flutter CLIflutterinstalled on your local machine. - Access to a Harness account with appropriate permissions to create registries and connectors.
Create a Dart artifact registry
- Interactive Guide
- Step-by-Step
- Navigate to the Artifact Registry module in your Harness project.
- Click on New Artifact Registry.
- In the Registry Type dropdown, select Dart Registry.
- Provide a Registry Name.
- Your registry name must start with a letter and can include
lowercase alphanumerics,_,.and-.
- Your registry name must start with a letter and can include
- Optionally, add a Description and Labels for better organization.
- Choose visibility between Public and Private. By default, the visibility is set to Private.
- Click Create Registry to finalize.
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.
- Interactive Guides
- Step-by-Step
Create an upstream proxy
Configure the upstream proxy in your registry
Create an upstream proxy
- In the Artifact Registry module, click the dropdown next to New Artifact Registry and select Upstream Proxy.
- Choose Dart Registry as the proxy type.
- Click Create Proxy to establish the connection.
Configure the upstream proxy in your registry
- In the Artifact Registry module, select an existing Artifact Registry.
- Select the Configuration tab.
- Under Advanced (Optional), select Configure Upstream.
- Select from the list of compatible proxies to add them to your registry.
- Click Save to save the configuration.
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
- Dart CLI
- Flutter CLI
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.
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
Configure Authentication
Step 1
Add authentication token to Flutter pub:
flutter pub token add https://pkg.harness.io/pkg/<account-id>/<dart-registry-name>/pub/
Step 2
Enter your <TOKEN> when prompted.
Replace <account-id> with your Harness account ID and <dart-registry-name> with your registry name.
Install a Dart Package with Flutter
Step 1
In your Flutter 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:
flutter pub get
Publish a Dart Package with Flutter
Step 1
In your Flutter 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 Flutter package
environment:
sdk: ">=3.0.0 <4.0.0"
Step 2
Then run:
flutter pub publish