- 
                Notifications
    You must be signed in to change notification settings 
- Fork 221
Description
Hi,
I have a monorepo project with multiple packages (27 to be more specific), and I'm using Melos to handle it. Unfortunately, after the recent project tech stack upgrade (Flutter from 3.29 to 3.35, Dart from 3.7.2 to 3.9.2, and different dependencies), I'm encountering a strange error while running the build_runner across the project with my melos steps.
buildrunner:clean:
    description: |
      Clean cache and run `build_runner` in all packages and apps
    steps:
      - for dir in apps packages; do find "$dir" -name ".dart_tool" -type d -exec rm -rf {} +; done
      - for dir in apps packages; do find "$dir" -name "build" -type d -exec rm -rf {} +; done
      - melos run pub:get
      - melos buildrunner:all
buildrunner:all:
    description: |
      Run `build_runner` to generate assets.
    run: |
      dart run build_runner build --delete-conflicting-outputs
    exec:
      failFast: true
      orderDependents: true
    packageFilters:
      dependsOn:
        - build_runner
Previously, with such code, we were able to successfully generate in parallel all the JSON serializations, api client, forms definition, local assets, and dependency injection files.
But now one builder is failing due to the non-existent files, which are part of another package (on which we have no dependency), and they are just not generated yet.
Example:
- We have a domain_package,data_packageandcommon_package
- domainhas no dependency on- dataand- common
- datahas dependency only on- domain
- and commonalso has dependency ondomain
- so there is no direct or transitive dependency between commonanddata
I run the build runner in a way as described above (a melos step), then:
- Previously generated files are being removed
- Next new files are successfully generated in the domainpackage
- And while generating dependency injection in datapackage andcommonpackage (they run in parallel, as there is no dependency between them), the build_runner incommonfails due to the lack of .g.dart files indata
[common_package]: E injectable_generator:injectable_builder on data_package|lib/src/featureX/datasource/featureX_change_broadcaster_impl.dart:
[common_package]:   AssetNotFoundException: data_package|lib/src/featureX/dto/featureX_message_response_dto.g.dart 
My expectation would be not to fail the build runner due to a lack of files that are not only in the package on which we are not dependent, but also are not needed at all for the specific runner, and they will be generated later.
As a workaround, I had to redefine my melos steps to run the specific build runners in a sequence, but now the build time has increased a lot, so I would prefer to return to the solution where I can run them in parallel.
My new build_runner steps:
buildrunner:clean:
  description: |
    Clean cache and run `build_runner` in all packages and apps (except widgetbook).
  steps:
    - for dir in apps packages; do find "$dir" -name ".dart_tool" -type d -exec rm -rf {} +; done
    - for dir in apps packages; do find "$dir" -name "build" -type d -exec rm -rf {} +; done
    - melos run pub:get
    - melos buildrunner:assets
    - melos buildrunner:api
    - melos buildrunner:forms
    - melos buildrunner:di
buildrunner:assets:
  description: |
    Run `build_runner` to generate assets.
  run: |
    dart run build_runner build --delete-conflicting-outputs \
      --build-filter **/*.gen.dart
  exec:
    failFast: true
  packageFilters:
    dependsOn:
      - flutter_gen_runner
buildrunner:api:
  description: |
    Run build_runner to generate api related files (json, api clients).
  run: |
    dart run build_runner build --delete-conflicting-outputs \
      --build-filter **/*.g.dart
  exec:
    failFast: true
  packageFilters:
    scope:
      - data_package
buildrunner:forms:
  description: |
    Run build_runner to generate forms.
  run: |
    dart run build_runner build --delete-conflicting-outputs \
      --build-filter **/*.gform.dart
  exec:
    concurrency: 1
    failFast: true
    orderDependents: true
  packageFilters:
    dependsOn:
      - reactive_forms_generator
buildrunner:di:
  description: |
    Run build_runner to generate dependency injection configuration.
  run: |
    dart run build_runner build --delete-conflicting-outputs \
      --build-filter **/*.config.dart
  exec:
    concurrency: 1
    failFast: true
    orderDependents: true
  packageFilters:
    dependsOn:
      - injectable_generator
My Flutter and Dart details:
[✓] Flutter (Channel stable, 3.35.7, on macOS 26.0.1 25A362 darwin-arm64, locale en-US) [2.8s]
    • Flutter version 3.35.7 on channel stable at /Users/pw/fvm/versions/3.35.7
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision adc9010625 (7 days ago), 2025-10-21 14:16:03 -0400
    • Engine revision 035316565a
    • Dart version 3.9.2
    • DevTools version 2.48.0
    • Feature flags: enable-web, no-enable-linux-desktop, no-enable-macos-desktop, no-enable-windows-desktop, enable-android, enable-ios,
      cli-animations, enable-lldb-debugging
Some package details that could be important:
_fe_analyzer_shared: ^91.0.0
analyzer: 8.4.0
build: 4.0.2
build_runner: ^2.9.0
flutter_gen_runner: ^5.12.0
injectable_generator: ^2.9.0
reactive_forms_generator: https://github.com/Devalfaz/reactive_forms_generator
retrofit_generator: ^10.0.5
source_gen: 4.0.2