Publish is one of the commands of the pub tool. Learn more about pub.
$ pub publish [--dry-run] [--force] [--server <url>]
This command publishes your package on
pub.dartlang.org for anyone to download and depend
on. For example, if your package is named transmogrify, it is listed on
http://pub.dartlang.org/packages/transmogify, and users can depend on it in
their pubspecs and get it via
pub get using something
dependencies: transmogrify: ">= 1.0.0 < 2.0.0"
When publishing a package, it’s important to follow the pubspec format and package layout conventions. Some of these are required in order for others to be able to use your package. Others are suggestions to help make it easier for users to understand and work with your package. In both cases, pub tries to help you by pointing out what changes will help make your package play nicer with the Dart ecosystem. There are a few additional requirements for uploading a package:
You must include a license file (named
COPYING, or some
variation) that contains an open-source license. We
recommend the BSD license,
which is used by Dart itself. You must also have the legal right to
redistribute anything that you upload as part of your package.
Your package must be less than ten megabytes large after gzip compression. If it’s too large, consider splitting it into multiple packages, or cutting down on the number of included resources or examples.
Your package should only have hosted dependencies. Git dependencies are allowed but strongly discouraged; not everyone using Dart has Git installed, and Git dependencies don’t support version resolution as well as hosted dependencies do.
Be aware that the email address associated with your Google account is displayed on pub.dartlang.org along with any packages you upload.
All files in your package are included in the published package, with the following exceptions:
Be sure to delete any files you don’t want to include (or add them to
.gitignore) before running
To be on the safe side,
pub publish lists all files it’s going to publish
for you to look over before it actually uploads your package.
For options that apply to all pub commands, see Global options.
With this, pub goes through the validation process but does not actually upload the package. This is useful if you want to see if your package meets all of the publishing requirements before you’re ready to actually go public.
With this, pub does not ask for confirmation before publishing. Normally, it shows you the package contents and asks for you to confirm the upload.
If your package has errors, pub doesn’t upload it and exits with an error.
In the event of warnings, your package is uploaded.
To ensure that your package has no warnings before uploading,
either don’t use
--force, or use
If you pass
--server followed by a URL, it attempts to publish the
package to that server. It assumes the server supports the same HTTP API that
This can be useful if you’re running your own local package server for testing. The main pub server is itself open source and available here.