| OLD | NEW |
| (Empty) |
| 1 <pre><code>$ pub upgrade [PACKAGE] | |
| 2 </code></pre> | |
| 3 | |
| 4 <p>Without any additional arguments, <code>pub upgrade</code> gets the latest ve
rsions of | |
| 5 all the dependencies listed in the <a href="pubspec.html"><code>pubspec.yaml</co
de></a> file in the | |
| 6 current working directory, as well as their <a href="glossary.html#transitive-de
pendencies">transitive | |
| 7 dependencies</a>, to the <code>packages</code> | |
| 8 directory located next to the pubspec. For example:</p> | |
| 9 | |
| 10 <pre><code>$ pub upgrade | |
| 11 Dependencies upgraded! | |
| 12 </code></pre> | |
| 13 | |
| 14 <p>When <code>pub upgrade</code> upgrades dependency versions, it writes a | |
| 15 <a href="glossary.html#lockfile">lockfile</a> to ensure that future <a href="pub
-get.html"><code>pub | |
| 16 get</code>s</a> will use the same versions of those dependencies. | |
| 17 Application packages should check in the lockfile to source control; this | |
| 18 ensures the application will use the exact same versions of all dependencies for | |
| 19 all developers and when deployed to production. Library packages should not | |
| 20 check in the lockfile, though, since they’re expected to work with a range
of | |
| 21 dependency versions.</p> | |
| 22 | |
| 23 <p>If a lockfile already exists, <code>pub upgrade</code> will ignore it and gen
erate a new | |
| 24 one from scratch using the latest versions of all dependencies. This is the | |
| 25 primary difference between <code>pub upgrade</code> and <code>pub get</code>, wh
ich always tries to | |
| 26 get the dependency versions specified in the existing lockfile.</p> | |
| 27 | |
| 28 <h2 id="upgrading-specific-dependencies">Upgrading specific dependencies</h2> | |
| 29 | |
| 30 <p>It’s possible to tell <code>pub upgrade</code> to upgrade specific depe
ndencies to the | |
| 31 latest version while leaving the rest of the dependencies alone as much as | |
| 32 possible. For example:</p> | |
| 33 | |
| 34 <pre><code>$ pub upgrade unittest args | |
| 35 Dependencies upgraded! | |
| 36 </code></pre> | |
| 37 | |
| 38 <p>Upgrading a dependency upgrades its transitive dependencies to their latest | |
| 39 versions as well. Usually, no other dependencies are updated; they stay at the | |
| 40 versions that are locked in the lockfile. However, if the requested upgrades | |
| 41 cause incompatibilities with these locked versions, they will be selectively | |
| 42 unlocked until a compatible set of versions is found.</p> | |
| 43 | |
| 44 <h2 id="getting-a-new-dependency">Getting a new dependency</h2> | |
| 45 | |
| 46 <p>If a dependency is added to the pubspec before <code>pub upgrade</code> is ru
n, it will | |
| 47 get the new dependency and any of its transitive dependencies and place them in | |
| 48 the <code>packages</code> directory. This is the same behavior as <code>pub get<
/code>.</p> | |
| 49 | |
| 50 <h2 id="removing-a-dependency">Removing a dependency</h2> | |
| 51 | |
| 52 <p>If a dependency is removed from the pubspec before <code>pub upgrade</code> i
s run, it | |
| 53 will remove the dependency from the <code>packages</code> directory, thus making
it | |
| 54 unavailable for importing. Any transitive dependencies of the removed dependency | |
| 55 will also be removed, as long as no remaining immediate dependencies also depend | |
| 56 on them. This is the same behavior as <code>pub get</code>.</p> | |
| 57 | |
| 58 <h2 id="upgrading-while-offline">Upgrading while offline</h2> | |
| 59 | |
| 60 <p>If you don’t have network access, you can still run <code>pub upgrade</
code>. Since pub | |
| 61 downloads packages to a central cache shared by all packages on your system, it | |
| 62 can often find previously-downloaded packages there without needing to hit the | |
| 63 network.</p> | |
| 64 | |
| 65 <p>However, by default, pub will always try to go online when you upgrade if you | |
| 66 have any hosted dependencies so that it can see if newer versions of them are | |
| 67 available. If you don’t want it to do that, pass the <code>--offline</code
> flag when | |
| 68 running pub. In this mode, it will only look in your local package cache and | |
| 69 try to find a set of versions that work with your package from what’s alre
ady | |
| 70 available.</p> | |
| 71 | |
| 72 <p>Keep in mind that pub <em>will</em> generate a lockfile after it does this. I
f the | |
| 73 only version of some dependency in your cache happens to be old, this will lock | |
| 74 your app to that version. The next time you are online, you will likely want to | |
| 75 run <code>pub upgrade</code> again to upgrade to a later version.</p> | |
| OLD | NEW |