Pub CLI Usage

Pub CLI Usage

This page describes the CLI commands to retrieve, publish, and upload packages after creating and configuring a Pub repository on Nexus.

Retrieve Pub Content

After configuring Pub to use the Nexus repository, use Dart or Flutter commands from your workspace.

dart pub get
flutter pub get
dart pub upgrade
flutter pub upgrade
dart pub downgrade

Where,

Example:

dart pub get
flutter pub get

Publish Pub Packages

You can publish your packages by using the dart pub publish command, the Components REST API, or the Nexus Repository UI. Sonatype recommends using the following dart pub publish command.

dart pub publish --server https://[NEXUS_URL]/repository/<REPO_NAME>

Where,

Example:

dart pub publish --server https://example.nexus.com/repository/pub-hosted

You can also publish using the Components REST API:

curl \
  -X POST \
  "https://[NEXUS_URL]/service/rest/v1/components?repository=<REPO_NAME>" \
  -u "USERNAME:PASSWORD" \
  -F "pub.asset=@{package-name}-{version}.tar.gz" \
  -F "pub.name={package-name}" \
  -F "pub.version={version}"

Where,

Example:

curl \
  -X POST \
  "https://example.nexus.com/service/rest/v1/components?repository=pub-hosted" \
  -u "publisher:[PASSWORD]" \
  -F "pub.asset=@example_package-1.0.0.tar.gz" \
  -F "pub.name=example_package" \
  -F "pub.version=1.0.0"

You can also upload Pub packages from the Nexus Repository UI.