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

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 :)

Related

Codemagic build process for a Flutter app: Could not find a file named "pubspec.yaml"

I am using Codemagic for the iOS build process for a Flutter app.
In the pubspec.yaml I am referring to a package dependency by pointing to a public repository like so:
dependencies:
flutter:
sdk: flutter
flutter_circular_slider:
git: https://github.com/tomoehlrich/flutter-circular-slider.git
It all works with local debugging and when building an apk with "flutter build apk" on Windows.
Codemagic though keeps giving me the following error message in the build step "Installing dependencies":
== Install Flutter dependencies ==
> flutter packages pub get
Resolving dependencies...
Could not find a file named "pubspec.yaml" in https://github.com/tomoehlrich/flutter-circular-slider.git 5d6d0c54e93766b27d30707bf20042b26894561c.pub
finished with exit code 1
Build failed :|Failed to install dependencies
I had Codemagic working before. The difference now to the working version was that I was referencing a different repository on Github.
I am trying to figure out why the build process cannot find the pubspec.yaml in https://github.com/tomoehlrich/flutter-circular-slider.git but in another fork of the same flutter package on Github.
Any hints are highly appreciated.
It seems that "resolved-ref" in pubspec.lock for the slider package was an outdated reference.
A new generation of pubspec.lock, sync to GitHub and start a new build process in Codemagic did the trick.

Which cocoapods version to use on Mac 10.12, If Restkit is the dependency

I was using 0.37.2 pod version on previous mac version. Its not working on Sierra. If i upgrade the pods, Restkit creates an issue for File not found. Tried all the possible answers to make Restkit work on new pod version but no success. If someone else got the same issue, what is the fix?
[!] Unable to load a specification for the plugin /Users/q/.rvm/gems/ruby-2.0.0-p648/gems/cocoapods-deintegrate-1.0.1
Analyzing dependencies
[!] The master repo requires CocoaPods 1.0.0 - (currently using 0.37.2)
Update CocoaPods, or checkout the appropriate tag in the repo.
http://blog.cocoapods.org/Sharding/
using old specs worked.
For people who want to continue using 0.x versions, we will be
replicating the Specs repo from the commit before the repo was
sharded. This means you can add:
source "https://github.com/CocoaPods/Old-Specs"
To the top of your Podfile, and CocoaPods will only use the archived
repo, instead of using the new repo structure. You will also need to
set your local Specs repo to a version before the transition:
cd ~/.cocoapods/repos/master/ git fetch origin master git checkout
v0.32.1

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.

Dart: pub get vs pub upgrade

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?

Updating libraries that aren't yet updated on pub

I want to use an updated library (Vadim Tsushko's mongo_dart at https://github.com/vadimtsushko/mongo_dart) but Pub (pub.dartlang.org) still has the older one, so a pub update doesn't help. I replaced mongo_dart in my packages directory. How can I update the package for all apps where it's referenced?
Thank you!
You may temporarily change pubspec.yaml to redirect dependency from pub.dartlang.org to concrete GitHub repository. For mongo_dart it is:
mongo_dart:
git: git://github.com/vadimtsushko/mongo_dart.git

Resources