Search code examples
flutterdartcode-generationbuild-runner

What to run instead of flutter packages pub run build_runner build --delete-conflicting-outputs


My Flutter app requires code generation for multiple reasons, such as mock generation for tests, or both Floor and Isar persistence back-ends require generation. I achieve this by executing flutter packages pub run build_runner build --delete-conflicting-outputs. I'm getting the message about the command being deprecated. However I'm wondering what command am I supposed to run instead.

Currently I'm using:

$ flutter packages pub run build_runner build --delete-conflicting-outputs
Deprecated. Use `dart run` instead.
Building package executable... (7.3s)
Built build_runner:build_runner.
[INFO] Generating build script completed, took 436ms
[INFO] Reading cached asset graph completed, took 227ms
[INFO] Checking for updates since last build completed, took 957ms
[WARNING] No actions completed for 18.2s, waiting on:
  - isar_generator on test/infer_sport_from_characteristics_id_test.dart
  - isar_generator on test/runn_rsc_test.dart
  - isar_generator on test/fitness_equipment_start_stop_workout_test.dart
  - isar_generator on test/fitness_equipment_process_record_test.dart
  - isar_generator on test/heart_rate_monitor_sensor_test.dart
  .. and 9 more

[INFO] Running build completed, took 29.4s
[INFO] Caching finalized dependency graph completed, took 117ms
[INFO] Succeeded after 29.6s with 15 outputs (97 actions)

This always re-generates the files.

First try:

$ dart run build_runner build --delete-conflicting-outputs
[INFO] Generating build script completed, took 427ms
[INFO] Reading cached asset graph completed, took 225ms
[INFO] Checking for updates since last build completed, took 979ms
[INFO] Running build completed, took 43ms
[INFO] Caching finalized dependency graph completed, took 137ms
[INFO] Succeeded after 189ms with 0 outputs (0 actions)

The problem is that this didn't regenerate any files whatsoever. No bueno.

Second try:

$ dart packages pub run build_runner build --delete-conflicting-outputs
Could not find a command named "packages".

Did you mean one of these?
  pub


Usage: dart <command|dart-file> [arguments]

Global options:
-v, --verbose               Show additional command output.
    --version               Print the Dart SDK version.
    --enable-analytics      Enable analytics.
    --disable-analytics     Disable analytics.
    --suppress-analytics    Disallow analytics for this `dart *` run without changing the analytics configuration.
-h, --help                  Print this usage information.

Available commands:
  analyze    Analyze Dart code in a directory.
  compile    Compile Dart to various formats.
  create     Create a new Dart project.
  devtools   Open DevTools (optionally connecting to an existing application).
  doc        Generate API documentation for Dart projects.
  fix        Apply automated fixes to Dart source code.
  format     Idiomatically format Dart source code.
  info       Show diagnostic information about the installed tooling.
  pub        Work with packages.
  run        Run a Dart program.
  test       Run tests for a project.

Run "dart help <command>" for more information about a command.
See https://dart.dev/tools/dart-tool for detailed documentation.

I'm on the beta channel and the latest build_runner (2.4.6).

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 3.13.0-0.3.pre, on Devuan GNU/Linux 6 (excalibur/ceres) 6.4.0-2-amd64, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.81.1)
[✓] Connected device (2 available)
[✓] Network resources

I looked at a few other SO entries, but I don't have any errors so far, and my CI/CD works, however I'd like to migrate until the command totally deprecates.


Solution

  • dart run build_runner build --delete-conflicting-outputs
    

    This changed with 2.1.3 of the build_runner package