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.
With explicit integration, a user needs to modify each
pubspec.yaml
file that uses or publishes a private package.- 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
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.cd mypackage
onepub pub private
# now publish your package to OnePub
dart pub publish
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
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.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.
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 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.
Linux
MacOs
Windows
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.
- 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)
- Users need to configure an environment variable
- Risk of users accidentally publishing a private to pub.dev
Last modified 1yr ago