How to use my dart packages private and not show on pub dart lang?
Asked Answered
P

5

28

I have dart packages that I don't want to publish to pub because of my company agreement. How to use my dart packages for only my company and not show on pub dart lang?

I've looked up on this link https://github.com/dart-lang/pub/issues/1050 but still need more information about that.

Phago answered 11/1, 2019 at 9:31 Comment(0)
B
27

If you publish a package to https://pub.dartlang.org it will show up. There is no way around that.

Alternatives.

You can use

  • path dependencies to packages stored on a local or network drive for example.
  • Git dependencies to packages stored in a Git repository
    • on a local or network drive
    • hosted on GitHub, GitLab, or any other Git server
  • run your own private Pub server.

See also

Bernardinebernardo answered 11/1, 2019 at 9:35 Comment(1)
The pub_server repository is archivedFelicitous
D
53

Günter Zöchbauer answer is correct but he hasn't provided it with examples.

So to use pub/package/lib without publishing on pub.dev :

1. Local - Save in some local folder

dependencies:
  library_name:
   path: /path/to/library_name

2. Hosted - Pushed on Github, Gitlab etc.

dependencies:
  library_name:
   git: https://github.com/username/library_name

Or to target specific branch

dependencies:
  library_name:
   git:
    url: https://github.com/username/library_name.git
    ref: dev    #branch name

Or to target specific commit

dependencies:
  library_name:
   git:
    url: https://github.com/username/library_name.git
    ref: e234072340    #commit reference id

Where 'library_name' has to be the same as the 'name' declared in pubspec.yaml of that pub.

Depression answered 17/6, 2021 at 17:26 Comment(3)
git submodule is another possibilityHarpsichord
What will happen if github repository is private. Do I need to provide a user name and password?Sherly
You can also specify folder: path: packages/packageAConey
B
27

If you publish a package to https://pub.dartlang.org it will show up. There is no way around that.

Alternatives.

You can use

  • path dependencies to packages stored on a local or network drive for example.
  • Git dependencies to packages stored in a Git repository
    • on a local or network drive
    • hosted on GitHub, GitLab, or any other Git server
  • run your own private Pub server.

See also

Bernardinebernardo answered 11/1, 2019 at 9:35 Comment(1)
The pub_server repository is archivedFelicitous
S
6

local :

To handle that, pub supports path dependencies.

dependencies:
  transmogrify:
    path: /Users/me/transmogrify

This says the root directory for transmogrify is /Users/me/transmogrify.

See : https://www.dartlang.org/tools/pub/dependencies

Swanson answered 11/4, 2019 at 2:13 Comment(1)
You will have to declare publish_to: none in you pubspec.yaml file, because using a path dependency is not allowed in a publishable library.Dipteran
N
5

Have a look at https://onepub.dev

It's a private package repository written specifically for dart.

You can publish to OnePub in a few commands

dart pub global activate onepub
onepub login
cd myproject
onepub pub private
dart pub publish

To add a dependency hosted on OnePub

cd aproject
onepub pub add myproject
dart pub get

In a CI/CD pipeline onepub allows you to export/import a security token to provide authentication.

There is a free version for small teams.

Nauseating answered 16/6, 2022 at 9:24 Comment(0)
P
1

You can also let someone else run the pub server (as a service): https://cloudsmith.io/l/dart-repository/

Although it's commercial (paid) for private repositories, it's free for public and open-source repositories. If you're looking for a serverless managed solution, it's the only alternative (as of writing).

Presumably answered 9/2, 2020 at 16:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.