Skip to content

[BUG]: flutter_gen_runner reads workspace root pubspec.yaml instead of package pubspec.yaml when using build_runner build --workspace #731

@ChaserVasya

Description

@ChaserVasya

Is there an existing issue for this?

  • I have searched the existing issues

Version

5.12.0

Command type

build_runner (Default)

What happened?

Environment

Component Version
Dart SDK 3.10.0 (stable)
Flutter 3.38.2 (stable)
build_runner 2.11.1
flutter_gen_runner 5.12.0

Disclaimer. Issue body generated by AI

Description

When running dart run build_runner build --workspace from a Dart workspace root, flutter_gen_runner reads the workspace root pubspec.yaml instead of the package's pubspec.yaml. Since the workspace root typically has no flutter_gen: or flutter: configuration, the builder:

  1. Uses the default output path (lib/gen/) and creates an empty directory at the workspace root
  2. Finds no assets to generate → produces no output
  3. Skips generating the correct output for the package

Root cause

In flutter_gen_runner.dart, the builder initializes with hardcoded relative paths:

final generator = FlutterGenerator(
    File('pubspec.yaml'),      // ← resolves relative to Directory.current
    buildFile: File('build.yaml'),
);

When using --workspace, Directory.current is the workspace root, not the individual package root. So File('pubspec.yaml') reads the workspace root's pubspec.yaml which has no flutter_gen: configuration.

Minimal reproduction structure

workspace_root/
├── pubspec.yaml              # workspace definition (no flutter_gen config)
└── apps/
    └── my_app/
        ├── pubspec.yaml      # has flutter_gen config + flutter assets
        ├── assets/
        │   └── image.png
        └── lib/

Root pubspec.yaml:

name: my_workspace
workspace:
  - apps/my_app

apps/my_app/pubspec.yaml (relevant sections):

dev_dependencies:
  flutter_gen_runner: ^5.12.0

flutter_gen:
  output: lib/generated/
  line_length: 80
  integrations:
    flutter_svg: true

flutter:
  assets:
    - assets/

Steps to reproduce

  1. Set up the workspace structure above
  2. Clean the build cache:
rm -rf .dart_tool/build
  1. Run from the workspace root:
dart run build_runner build --workspace
  1. Observe:
ls lib/gen/          # ← empty directory created at workspace root (default output path)
ls apps/my_app/lib/generated/   # ← expected output NOT generated

Expected behavior

  • flutter_gen_runner reads apps/my_app/pubspec.yaml for the my_app package
  • Generates apps/my_app/lib/generated/assets.gen.dart (per the flutter_gen.output config)
  • Does NOT create anything at the workspace root

Actual behavior

  • flutter_gen_runner reads the workspace root pubspec.yaml (no flutter_gen: section)
  • Creates an empty lib/gen/ directory at the workspace root (default output path)
  • Does not generate assets.gen.dart for the package — build log shows no-op
  • Pre-existing generated files survive only because they are committed to git

Suggested fix

Instead of File('pubspec.yaml'), the builder should resolve the pubspec path relative to the package being built. The BuildStep provides inputId.package which can be used to find the correct package root.

Workaround

Run build_runner per-package instead of using --workspace:

cd apps/my_app && dart run build_runner build

Relevant a pubspec.yaml.

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions