# 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.

{% hint style="success" %}
**Recommendation:** It is recommended to use explicit Integration unless you have an Enterprise license.
{% endhint %}

The OnePub team recommends 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 pub private` command. The outcome is the same, using the `onepub pub private` command is faster.

#### Use the onepub private command.

```bash
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:

![](/files/EU1CBx1CXEul9UBGiDoK)

Add a `publish_to` key to your `pubspec.yaml`.

```yaml
name: onepub
version: 1.1.0

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

```

Now publish your package

```bash
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:

```bash
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 (or add)  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:

![](/files/G00Rljutk8j2fxBYP7cx)

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

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

{% hint style="danger" %}
If your dart version is older than 2.15, then you must use the older hosted format.
{% endhint %}

```yaml
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:

![](/files/9CnKFcvw0TfY1e6fYSAJ)

Now add the PUB\_HOSTED\_URL environment variable to your system.

{% tabs %}
{% tab title="Linux" %}
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.
{% endtab %}

{% tab title="MacOs" %}
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.
{% endtab %}

{% tab title="Windows" %}
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.
{% endtab %}
{% endtabs %}

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

This method is doesn't interfere with your ability to get  public packages from pub.dev.

#### 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 package to pub.dev


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onepub.dev/guides/installing/cli-integration/implicit-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
