Pergunta

When a new Dart package is published, how can I install the updated version?

Foi útil?

Solução

The DartEditor calls pub get automatically when the file pubspec.yaml is updated.

You may call it manually (e.g. when you for example checked out a project from GitHub without modifying any file)

  • by using the context menu Pub Get in DartEditor on the file pubspec.yaml
  • by calling pub get on the command line in the package directory where the file pubspec.yaml is stored.

pub get downloads the package version noted in the file pubspec.lock (in the package root directory) or the most recent version that fulfills your version constraint (0.0.1 in your example could be any for 'most recent') if pubspec.lock doesn't exist. pub get/pub upgrade create the file pubspec.lock if it doesn't yet exist and save the versions of the downloaded packages it just downloaded.

Check for updated packages and download them using

  • context menu Pub Upgrade in DartEditor on the file pubspec.yaml
  • pub upgrade on the command line in the package directory where the file pubspec.yaml is stored.

pub upgrade downloads the most recent version that fulfills your version constraints and stores the downloaded version in the file pubspec.lock.

pub get/pub upgrade prefers stable releases (version numbers that don't contain a -) like 0.0.1 or 1.2.0+1 over pre-releases like 0.0.2-1 or 1.2.1-1 if any is available that fulfulls your version constraint.

If you want a pre-release you have to tighten the version constraint so that only the pre-release fulfills your constraints (like angular: '>=1.2.1')

pub upgrade may show an output like

analyzer 0.10.5 (9 newer versions available)

Which indicates that there are 9 prerelease builds available that are newer than the downloaded stable build.

The version constraint for your dependency needs to fulfill the version constraints of all your dependencies dependencies (E.g. if you add the dependencies observe and polymer where polymer depends on observe itself).

You can force pub get/pub upgrade to a version that violates your dependencies dependency by defining the dependency with a version constraint under dependencies_override: instead of dependencies: in pubspec.yaml.

You may also add dev_dependencies (e.g. unittest) which are only downloaded when they are defined in your package but ignored when they are only defined in one of your dependencies.

You see, this is an advanced topic even for seasoned Dart developers.

Outras dicas

If you are a seasoned Dartisan, this question might seem so trivial to not be worth asking, but coming from a Java world (where my students and I are used to downloading .jars manually and then (sometimes) having to copy them over into our projects) it is a greenhorn question that is natural to ask. Here is the context: two days ago v0.9.5 of angular came out and so I made a mental note to upload the libraries in our local projects.

Well, it seems that all we need is an appropriately defined pubspec.yaml file, and the Dart pub package manager does the rest. In the Dart Editor, I guess that dependencies get updated on a project refresh or when it is (re-)built. In our projects we happened to have, e.g., a pubspec.yaml file like this:

name: angular_dart_demo
version: 0.0.1
dependencies:
  angular: any

(as opposed to, say, angular: ">=0.9.0 <0.10.0") which allowed the Pub manager to go fetch the latest angular. Effortless. Nice.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top