dart-lang / source_gen

Automatic source code generation for Dart
https://pub.dev/packages/source_gen
BSD 3-Clause "New" or "Revised" License
486 stars 106 forks source link

Can't target non null-safety libraries #532

Closed erlandvr closed 3 years ago

erlandvr commented 3 years ago

We have a large codebase that we're trying to keep up to date but keep the null safety unsound. When we update all dependencies we get errors like this:

[SEVERE] json_serializable:json_serializable on lib/data/json/model/votas/update_status_message_dto.dart (cached):
Generator cannot target libraries that have not been migrated to null-safety.
package:vts/data/json/model/votas/update_status_message_dto.dart:11:7

We believe that the library that gets targeted and is not null-safe is our own application while using json_serializer.

here is our pubsbec.yaml


name: vts
description: {Application Name}
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 9.0.5
environment:
  sdk: ">=2.7.0 <3.0.0"
#  flutter: "1.17.4"
dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  fimber: ^0.6.1
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.3
  chopper: ^4.0.0
  logging: ^1.0.1
  get_it: ^7.1.3
  device_info: ^2.0.2
  json_annotation: ^4.0.1
  hive: ^2.0.4
#  hive_flutter:
#    git:
#      url: https://github.com/hivedb/hive.git
#      path: hive_flutter
#      ref: d4f96f448c408bde8130cb4c0ba59004e72f37e6
  equatable: ^2.0.2
  intl: ^0.17.0
  meta: ^1.3.0
  path_provider: ^2.0.2
  connectivity: ^3.0.6
  moor_flutter: ^4.0.0
  moor: ^4.3.2
  open_file: ^3.2.1
  overlay_support: ^1.2.1
  xplatform:
    git:
      url: https://github.com/digitalrmdy/xplatform.git
      ref: null-safety
  calendar_manager:
    git:
      url: https://github.com/digitalrmdy/calendar-manager.git
      ref: null-safety
  localization_annotation:
    git:
      url: https://github.com/digitalrmdy/localization-builder.git
      ref: null-safety
      path: localization_annotation
  provider: ^5.0.0
  package_info: ^2.0.2
  align_positioned: ^2.0.1
  password:
    git:
      url: https://github.com/timvanginderen/password-dart.git
  image_picker: ^0.7.5+3
  url_launcher: ^6.0.4
  map_launcher: ^2.0.0
  flutter_sticky_header: ^0.6.0
  qr_flutter: ^4.0.0
  event_bus: ^2.0.0
  qr_mobile_vision:
    git:
      url: https://github.com/timvanginderen/flutter_qr_mobile_vision.git
  firebase_messaging: 10.0.0
#  flutter_widgets: ^0.1.11
  visibility_detector: ^0.2.0
  scrollable_positioned_list: ^0.1.10
  flutter_app_badger: ^1.2.0
  iban: ^1.0.0
  flutter_html: ^2.0.0
  background_fetch: ^1.0.0-nullsafety.2
  basic_utils: ^3.1.0
dev_dependencies:
  flutter_test:
    sdk: flutter
#  localization_builder:
#    git:
#      url: https://github.com/digitalrmdy/localization-builder.git
#      path: localization_builder
#  mockito_builder:
#    git:
#      url: https://github.com/digitalrmdy/mockito-builder.git
#  intl_translation: ^0.17.8
  build_runner: ^2.0.4
  chopper_generator: ^4.0.0
  json_serializable: ^4.1.3
  mockito: ^5.0.9
  flutter_launcher_icons: ^0.9.0
#  moor_generator: ^2.2.0
#  moor_ffi: ^0.3.1
  hive_generator: ^1.1.0
#    git:
#      url: https://github.com/hivedb/hive.git
#      path: hive_generator
#      ref: d4f96f448c408bde8130cb4c0ba59004e72f37e6
flutter_icons:
  android: true
  ios: true
  image_path: "assets/icon/icon.png"
  adaptive_icon_background: "#006FBD"
  adaptive_icon_foreground: "assets/icon/icon_foreground.png"
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg
  assets:
    - assets/images/
  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.
  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages
  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages
  fonts:
    - family: Lato
      fonts:
        - asset: fonts/Lato-Regular.ttf
        - asset: fonts/Lato-Italic.ttf
          style: italic
        - asset: fonts/Lato-Bold.ttf
          weight: 700

Does this mean it is not possible to run our application in an unsound null-safe version? 
jakemac53 commented 3 years ago

You need to use an older version of json_serializable in order for this to work - the previous version supports apps that are not oped in to null safety. The new version only supports opted in projects.

jakemac53 commented 3 years ago

Just to clarify I believe you need a version <4.0.0 (3.5.1 being the newest one before that).

erlandvr commented 3 years ago

Am I correct to assume, that not updating our code to sound null-safety means we will not be able to update to a newer version of json_serializable in the future.

natebosch commented 3 years ago

Am I correct to assume, that not updating our code to sound null-safety means we will not be able to update to a newer version of json_serializable in the future.

That is correct. The json_serializable generator made a breaking change to require null safe input code in order to use the latest version.

cc @kevmoo