Harness Artifact Registry provides support for Dart packages, allowing you to host private Dart and Flutter libraries.
Overview
Dart registry features:
- Standard pub.dev protocol
- Automatic metadata extraction from
pubspec.yaml
.tar.gz package format support
- Version management following SemVer
- Integration with pub and flutter CLI
Pushing Dart packages
Use the hc artifact push dart command:
hc artifact push dart <registry-name> <package-file-path> \
--pkg-url <pkg-url>
How it works
The CLI automatically:
- Validates the package archive format
- Extracts
pubspec.yaml from the archive
- Reads package name and version
- Uploads the package to the registry
Creating Dart packages
Create pubspec.yaml
Define your package metadata:name: my_package
version: 1.0.0
description: A useful Dart package
environment:
sdk: '>=3.0.0 <4.0.0'
dependencies:
# Your dependencies
dev_dependencies:
test: ^1.24.0
Package your library
Create the package archive:# Using dart pub
dart pub publish --dry-run
# Or create manually
tar -czf my_package-1.0.0.tar.gz .
Upload to registry
Push the package:hc artifact push dart my-registry ./my_package-1.0.0.tar.gz \
--pkg-url https://app.harness.io/registry/pkg
Installing Dart packages
Configure pub to use your Harness registry:
In pubspec.yaml
Add a custom dependency:
dependencies:
my_package:
hosted:
name: my_package
url: https://<registry-url>/
version: ^1.0.0
Using pub credentials
Configure authentication:
# Set up credentials
dart pub token add https://<registry-url>/
# Enter your Harness API token when prompted
Install dependencies
dart pub get
# Or for Flutter projects
flutter pub get
Examples
# Package and push a Dart library
tar -czf my_package-1.0.0.tar.gz . --exclude='.git' --exclude='.dart_tool'
hc artifact push dart my-registry ./my_package-1.0.0.tar.gz \
--pkg-url https://app.harness.io/registry/pkg
Pubspec.yaml requirements
The pubspec.yaml must contain name and version fields
Minimal configuration:
name: my_package
version: 1.0.0
environment:
sdk: '>=3.0.0 <4.0.0'
For Flutter packages:
name: my_flutter_package
version: 1.0.0
description: A Flutter package
environment:
sdk: '>=3.0.0 <4.0.0'
flutter: '>=3.0.0'
dependencies:
flutter:
sdk: flutter
Package structure
Typical Dart package structure:
my_package/
├── lib/
│ └── my_package.dart
├── test/
│ └── my_package_test.dart
├── pubspec.yaml
├── README.md
├── CHANGELOG.md
└── LICENSE
CI/CD integration
- name: Setup Dart
uses: dart-lang/setup-dart@v1
- name: Package and publish
run: |
dart pub get
dart test
tar -czf my_package-${{ github.ref_name }}.tar.gz .
hc artifact push dart my-registry ./my_package-*.tar.gz \
--pkg-url https://app.harness.io/registry/pkg
env:
HARNESS_API_KEY: ${{ secrets.HARNESS_API_KEY }}
publish:
image: dart:stable
script:
- dart pub get
- dart test
- tar -czf my_package-$CI_COMMIT_TAG.tar.gz .
- hc artifact push dart my-registry ./my_package-*.tar.gz --pkg-url $PKG_URL
variables:
HARNESS_API_KEY: $HARNESS_TOKEN
only:
- tags
Version constraints
Dart uses Semantic Versioning with caret syntax:
^1.0.0 - Compatible with 1.0.0, allows >=1.0.0 <2.0.0
>=1.0.0 <2.0.0 - Explicit range
1.0.0 - Exact version
any - Any version (not recommended)
Troubleshooting
pubspec.yaml validation failed
Ensure your pubspec.yaml is valid:# Validate pubspec.yaml
dart pub publish --dry-run
The archive filename should match the package name and version:# ✅ Correct
my_package-1.0.0.tar.gz # matches pubspec.yaml name: my_package, version: 1.0.0
Re-add your pub token:dart pub token add https://<registry-url>/
# Enter your Harness API token
See also