k-paxian / dart-json-mapper

Serialize / Deserialize Dart Objects to / from JSON
https://pub.dev/packages/dart_json_mapper
Other
400 stars 33 forks source link

Can't add sources to `build.yaml` using `flutter_translate_annotations` package #201

Closed AlaaEldeenYsr closed 1 year ago

AlaaEldeenYsr commented 1 year ago

I'm using a package for langs translations model generating, It requires to add that block of configurations in the build.yaml file https://github.com/Jesway/Flutter-Translate/wiki/3.-Generating-statically-typed-localization-keys

targets:
  $default:
    sources:
      include:
        - assets/i18n/**
        - lib/**
targets:
  $default:
    builders:
      dart_json_mapper:
        generate_for:
          # here should be listed entry point files having 'void main()' function
          - lib/main.dart

      # This part is needed to tell original reflectable builder to stay away
      # it overrides default options for reflectable builder to an **empty** set of files
      reflectable:
        generate_for:
          - no/files
    sources:
      include:
        - assets/i18n/**
        - lib/**

This, in turn, leads to a failure in dart_json_mapper

AlaaEldeenYsr commented 1 year ago

@k-paxian any help

k-paxian commented 1 year ago

Any error message or quick reproduction project?

AlaaEldeenYsr commented 1 year ago
[INFO] Running build...
[INFO] 1.0s elapsed, 0/1 actions completed.
[INFO] 2.1s elapsed, 0/1 actions completed.
[INFO] 3.1s elapsed, 0/1 actions completed.
[INFO] 4.2s elapsed, 0/1 actions completed.
[INFO] 15.0s elapsed, 0/1 actions completed.
[WARNING] No actions completed for 15.1s, waiting on:
  - dart_json_mapper on lib/main.dart

[SEVERE] dart_json_mapper on lib/main.dart:

AssetNotFoundException: ya_schools_parent_app|pubspec.yaml
[INFO] 16.2s elapsed, 33/49 actions completed.
[INFO] 17.2s elapsed, 65/81 actions completed.
[INFO] 18.2s elapsed, 96/111 actions completed.
[INFO] 19.2s elapsed, 129/144 actions completed.
[INFO] 20.3s elapsed, 167/182 actions completed.
[INFO] 21.5s elapsed, 200/215 actions completed.
[INFO] 22.5s elapsed, 286/287 actions completed.
[INFO] Running build completed, took 23.0s

[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 167ms

[SEVERE] Failed after 23.2s

When i comment the flutter_translate_gen configurations it works well, But when i add both configs of flutter_translate_gen and dart_json_mapper it throw the above error

targets:
  $default:
    builders:
      dart_json_mapper:
        generate_for:
          # here should be listed entry point files having 'void main()' function
          - lib/main.dart

      # This part is needed to tell original reflectable builder to stay away
      # it overrides default options for reflectable builder to an **empty** set of files
      reflectable:
        generate_for:
          - no/files
    # sources:
    #   include:
    #     - assets/i18n/**
    #     - lib/**
AlaaEldeenYsr commented 1 year ago

I created that quick reproduction project for you @k-paxian json_mapper_conflict.zip

k-paxian commented 1 year ago

Thanks 👍

k-paxian commented 1 year ago

Well that's a pure configuration issue here.

While using specific sources configuration, which is by default ** here is the docs image

So, while specifying a restricted list of sources you are reducing ability for dart_json_mapper builder and other builders to discover entire package sources **. Specifically dart_json_mapper builder needs to have an access to the pubspec.yaml of your package.

So to fix your case you just need to include pubspec.yaml to the sources list:

targets:
  $default:
    sources:
      include:
        - assets/i18n/**
        - lib/**
        - $package$
        - pubspec.yaml

Let me know if this helps

AlaaEldeenYsr commented 1 year ago

Thank you @k-paxian it worked well