Dart: pub get vs pub upgrade - dart

According to the pub get docs the main difference between pub get and pub upgrade is:
If a lockfile already exists, pub get uses the versions of dependencies locked in it if possible. If a dependency isn’t locked, pub will get the latest version of that dependency that satisfies all the version constraints. This is the primary difference between pub get and pub upgrade, which always tries to get the latest versions of all dependencies.
But this leaves me with a few questions.
What do they mean by "If a dependency isn't locked...? Locked?!? Like in version control? File system lock? What is this lock of which they speak?
Still not clearly understanding the difference between these two commands. Are they saying that pub get takes version constraints into account, and that pub upgrade doesn't?

It is locked when the pubspec.lock file contains an entry for this dependency.
You can change the dependency in pubspec.lock manually to specify exactly what version you want to use.
pub upgrade checks for the newest version that fits your pubspec.yaml configuration and updates your pubspec.lock file automatically.
when pubspec.lock is checked in with your package code in a CVS repository you are able to later reproduce the exact same setup as you had when you checked in your code even when your pubspec.yaml allowed a wider range of versions for a dependency.
see also
Upgrading a dependency
In Dart and Pub, should I add pubspec.lock to my .gitignore?

Related

How do you force 'pub get' to get latest from git?

I have a git dependency in my pubspec.yaml file, how can I force it to be updated when new changes occur in the git repo?
flutter pub get / pub get
It does not get the latest, as it is in .pub-cache/git/
Is there a way to force a specific dependency to update from a git repo referenced in pubspec.yaml?
In your pubspec.yaml, you can specify a particular git commit:
dependencies:
http2:
git:
url: https://github.com/dart-lang/http2.git
ref: c31df28c3cf076c9aacaed1d77f45b66bb2e01a6
Or if you specify only a branch in "ref":
dependencies:
http2:
git:
url: https://github.com/dart-lang/http2.git
ref: master
You need to force the update with flutter packages upgrade
Use
flutter packages upgrade
to get latest.
flutter packages get
only gets latests the first time and writes the resolved versions into pubspec.lock
Subsequent flutter packages get runs then try to get the versions listed in pubspec.lock,
while flutter packages upgrade always ignores pubspec.lock
Run flutter clean and then pub get (if using flutter then add flutter before pub)
Ensure to update your package's version number; if the version is the same as the last commit, the package won't get updated.
run pub upgrade
if it still doesn't work you can run pub cache repair which reinstalls all your packages
EDIT
ensure dependency is not in dev_dependencies section (yup, that was today!)
flutter packages upgrade upgrades all packages' sub-version which might not be the thing you are looking for (using some specific package version for some reason etc.). pub cache repair gets the job done by reinstalling all the packages but it also takes time. Working with refs has disadvantages like missing the most current updates on a branch.
There are 2 other options/hacks to avoid all this:
delete package info from pubspec.lock and run flutter pub get
update ref value to most current commit's hash value. run flutter pub get then rewrite your branch name again to your ref value.
Fast Solution: Just change the repo name and run pub get :)

Dart versioning - no matching version

In my angular2 project I don't manage to add the "google_maps: 3.1.0" dependency.
It seems that this library is in conflict with "angular2: 2.0.0-beta.20".
The error message is :
Package code_transformers has no versions that match >=0.4.1 <0.5.0 derived from:
- build 0.3.0 depends on version ^0.4.1
However, "google_maps: 3.1.0" do not contain "code_transformers" or "build" package in its dependencies and transitive dependencies.
Thanks for your help.
This means that pub get or pub upgrade could not find a set of dependencies that are compatible.
Try to commenting out all dependencies except two and run pub get or pub upgrade again. Then add one dependency and run again and so on until you get the error. This way you can figure out what dependency causes the problem.
Don't use any as dependency constraint in your pubspec.yaml. This is known to cause troubles because pub has to analyze the whole search space which is gigantic.

Dart's pub get command can't find latest versions of some dependencies

I've noticed on a few occasions that when I setup some dependencies in my pubspec.yaml pointing to the latest version, they aren't found when I run pub get.
For instance, the dependency source_gen. The latest version of source_gen is clearly 0.5.0+1. So I'll setup my pubspec.yaml file as follows:
dependencies:
source_gen: "^0.5.0+1"
Then I run pub get, and I get the following error:
Resolving dependencies...
Package source_gen has no versions that match >=0.5.0+1 <0.6.0 derived from:
- ServerErrors depends on version ^0.5.0+1
I tried several of the most recent versions, without much luck. Finally if I do the following:
dependencies:
source_gen: any
and then run pub get, source_gen version 0.4.7 is installed. I'm not sure I understand why. I'm using the dart sdk version 1.16.0. This is the second dependency I've had this issue with and I'm a little confused.
EDIT: As requested by Gunter, the full list of my dependencies:
dependencies:
http: "^0.11.3+7"
dartson: "^0.2.5"
intl: "^0.12.7+1"
mailer: "^1.0.0"
That's a known issue of pub. This means pub just wasn't able to resolve a compatible set of dependencies. Unfortunately the error message is misleading.
pub also prints the same error when one of the dependencies isn't compatible with the used Dart SDK version.

Could not find pubspec.yaml in unittest 0.11.0+5

I'm running pub get and its reporting that it can't find a pubspec.yaml file in unittest package, anyone seen this before? Im on Dart Editor version 1.8.0.dev_00_00 (DEV) Dart SDK version 1.8.0-dev.0.0
The downloaded package in
C:\Users\daniel\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\unittest-0.11.0+5
didn't have a pubspec.yaml file in it, and using pub cache repair wouldn't work for that very reason also so I had to manually open the directory and delete it then when I did a new pub get it did work. Sounds like cache repair might need tweaking to make it delete any corrupted packages that didnt have their pubspecs downloaded with them and I beleive this broken state was created by me running a pub get whislt a pub get was already in progress on the same pubspec.yaml file, so probably best you avoid doing that.

pub install does not work in Dart

I am trying to install glmatrix using pub install. My OS is Windows 7 and I have Git installed.
Here is my pubspec.yaml
name: WebGLTut1
description: A sample application
dependencies:
glmatrix:
git: git://github.com/pjako/glmatrix.dart.git
When I run pub install I get the following error:
Running pub install ... Pub install fail, FormatException: Could not
parse "git://github.com/pjako/glmatrix.dart.git".".
I googled a while to find a solution but couldn't. Please help.
UPDATE#1:
I found the problem. There has to be a TAB/Space when specifying git: url in pubsec.yaml as follows.
glmatrix:
git: git://github.com/pjako/glmatrix.dart.git
This solved the previouse problem of FormatException. But now when I run pub install again it throws theis error.
Running pub install ... Pub install fail, Git failed.
As you identified you update, yaml files are whitespace sensitive; that's why you don't have to use lots of curly braces like json. :)
I see a few of possible problems here:
First
Glmatrix doesn't appear to have its own pubspec defined. Libraries participating in the package system much declare a pubspec file with the name property defined. The name is important because pub uses it when you declare your dependencies. Let's say you had a project called toast with the following simple pubspec:
name: butter
version: 0.0.0
Then you would need to declare your dependency to that project like so:
dependencies:
butter:
git: git://github.com/foo/toast.git
Have the project owner make the changes or fork it yourself, add the pubspec, and then reference your fork in your pubspec.
Second
Glmatrix is does not conform to the pubspec package layout conventions (your own projects should also conform to this). Although I believe that pub may handle non-conforming layouts currently, it may not in the future. So again, you can either ask the project owner to fix, or fork and fix it yourself.
Third
Since you are on windows, make sure git is in your system PATH variable. If you are using the bash shell, git will work, but it's not going to work outside of bash (like from Dart editor) until you add it to your PATH.

Resources