-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Breaking change: pubspec.yaml must contain a Dart SDK constraint #44072
Comments
Posted to Dart announce: https://groups.google.com/a/dartlang.org/forum/#!topic/announce/TyaUVp4hXwU |
Rather than merely fail with an error that tells the user what to do, can we provide a command that will do it for them? Adding something to a YAML file is something eminently automatable. Maybe we should even do it automatically, like we do |
@Hixie I fear that having We could do a As for modifying YAML, it's not trivial, but we had a GSoC project create |
We might want to look into adding a quick fix in the analysis server for this case. |
marking this as Approved |
How about adding a key to pubspec: |
I think the upside is that once migrated, you'll probably stop thinking about this. A boolean would instead continue to be a thing going forward. |
Fix pubspec.yaml to conform with latest spec: dart-lang/sdk#44072
Closing this as this is already in Dart 2.12 |
Background
Dart apps and packages often use a
pubspec.yaml
file to declare various metadata such as dependencies. It can also contain a Dart SDK constraint such as:This expresses that the app/package requires a Dart SDK that is at least 2.10.0, and strictly less than 3.0.0. This is commonly used to express that the code uses a feature only available in more recent Dart releases, for example Dart 2.7 if using extension methods. The SDK constraint is documented here: https://dart.dev/tools/pub/pubspec#sdk-constraints
Currently it is allowed to omit this SDK constraint. In that case Dart interprets this as having a lower constraint that is the same as the version of the Dart SDK being used.
What is the change
We're making it an error for apps to have a
pubspec.yaml
that doesn't have this SDK constraint specified. Concretely, for a pubspec not containing the Dart SDK constraint, thepub
/dart pub
/flutter pub
command will abort dependency resolution for apps and fail with an error like:Why are we making this change
For the Dart null safety feature we're relying on the SDK constraint to tell if a Dart app/package us using null safety semantics or not. Because of the current defaulting to current SDK version when the SDK constraint is omitted, this results in such projects being opted-in to null safety implicitly. This in turn results in lots of null safety errors.
Making the SDK constraint required ensures that all apps and packages are forced to make a choice about what Dart version they need.
Effect of the change
All existing
pubspec.yaml
files that don't contain an SDK constraint will start to see resolution errors. They will need to add an SDK constraint like this to their pubspec. After adding this they will continue to run as before.Timeline
This change is blocking the progress on null safety, so the change will be made immediately in the Dart master channel (where the Dart 2.12 version is underway).
The text was updated successfully, but these errors were encountered: