LogoLogo
  • OnePub
  • Guides
    • Installing
      • Install CLI tools
      • Register
      • Invite a member
      • Accept an Invite
      • CLI integration
        • Manually add publish_to
        • Implicit Integration
      • IDE integration
        • Android Studio
        • Visual Studio Code
      • Pre Dart 2.15
      • Pre Dart 2.12
    • Searching
    • Watching packages
    • Publishing Packages
      • The hard way
    • Private dependencies
      • The hard way
    • CLI Tools
      • login
      • logout
      • doctor
      • export
      • import
      • pub add
      • pub private
      • pub global activate
      • pub global deactivate
    • CI/CD
    • SSH
    • Docker
    • Community Choice Awards
  • Fundamentals
    • Members
    • Teams
    • Roles
    • Naming Packages
  • Workflows
    • Distributing to Customers
      • Purchase a Customer Distribution License
      • Security considerations
      • Publish a package
      • Invite a customer
      • Customer installation instructions
      • Conditions Apply
    • For Support
    • Setting up CI/CD
    • Vendoring Dependencies
    • Switching Organisations
    • Creating a Team Leader
  • FAQ
    • Is GST/VAT/Sales Tax applicable?
    • Does OnePub.dev have access to my personal information?
    • What is your SLA?
    • How do I get support?
    • How do I use OnePub from my CI/CD environment?
    • How to invite team members to join OnePub
    • How to publish a private package
    • 401: Unauthorized
  • Solved by OnePub
  • Data Retention Policy
  • Payments
Powered by GitBook
On this page
  • Explicit Integration
  • Configure a package to be published to OnePub
  • Configure a OnePub dependency
  • Implicit Integration

Was this helpful?

  1. Guides
  2. Installing
  3. CLI integration

Implicit Integration

In this guide, users will learn tips and recommendations on using OnePub with the Dart CLI tools.

OnePub supports both explicit and implicit integration.

Recommendation: It is recommended to use explicit Integration unless you have an Enterprise license.

Personally, we recommend using Explicit Integration as it allows the users to make the most of OnePub at the cost of a minor change to each of their pubspec.yaml files.

Explicit Integration

With explicit integration, a user needs to modify each pubspec.yaml file that uses or publishes a private package.

Pros

  • Only requires the user to run onepub login and they are fully configured

  • using publish_to in your pubspec stops the package from being accidentally published to pub.dev

  • Dependencies work for other users without any environment configuration

  • No configuration is required for your IDE

Cons

  • Users need to explicitly configure each Private Dependency

Configure a package to be published to OnePub

You can edit your pubspec.yaml file manually or use the onepub private command. The outcome is the same, using the onepub command is faster.

Use the onepub private command.

cd mypackage
onepub pub private
# now publish your package to OnePub
dart pub publish

Manually edit pubspec.yaml

Login to OnePub and copy the `publish_to:` url from the profile page:

Add a publish_to key to your pubspec.yaml.

name: onepub
version: 1.1.0

# Set onepub as the publish target.
publish_to: https://onepub.dev/api/xxxxxxx

Now publish your package

cd mypackage
dart pub publish

Configure a OnePub dependency

Once you have published a package to OnePub you are going to want to update your projects to use the package from OnePub.

You can either manually edit your pubspec.yaml or use the onepub cli tools to do the work for you.

Use the onepub add command

To add or change a package dependency to get the package from OnePub run:

cd <my project>
onepub pub add [--dev] <package>

Use the --dev switch to add the package as a dev dependency.

If the package already exists as a dependency the onepub will simply update the hosted-url to point to OnePub.

Manually configure a OnePub dependency

For each project that depends on a private package, you can add a hosted key.

Copy the 'publish_to' URL from your profile page:

Now paste it into the 'hosted' key for the package.

dependencies: 
  my_private_package:
    version: 1.0.2
    hosted: https://onepub.dev/api/xxxxxxxx

If your dart version is older than 2.15, then you must use the older hosted format.

dependencies: 
  my_private_package:
    version: 1.0.2
    hosted: 
      name: my_private_package
      url: https://onepub.dev/api/xxxxx

Implicit Integration

Implicit Integration involves setting the PUB_HOSTED_URL environment variable.

Copy the publish_to url from your profile page:

Now add the PUB_HOSTED_URL environment variable to your system.

Add an export statement to your ~/.bashrc file:

export PUB_HOSTED_URL=https://onepub.dev/api/xxxxxxx

Restart your shell and check the environment variable is available.

Add an export statement to your ~/.zshrc file:

PUB_HOSTED_URL=https://onepub.dev/api/xxxxxxx

Restart your shell and check the environment variable is available.

Added the environment variable to your registry.

export PUB_HOSTED_URL=https://onepub.dev/api/xxxxxxx

Restart your shell and check the environment variable is available.

Once it is configured, all requests made by the pub command are sent to your OnePub private repo.

This method is still able to get public packages.

Pros

  • No need to configure each package and dependency

  • Restrict devs to only using packages from verified publishers (Enterprise Edition)

  • Constrain what packages your team can use via a OnePub curated list (Enterprise Edition)

Cons

  • Users need to configure an environment variable

  • Risk of users accidentally publishing a private to pub.dev

PreviousManually add publish_toNextIDE integration

Last updated 2 years ago

Was this helpful?