-
-
Notifications
You must be signed in to change notification settings - Fork 175
Description
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:
- Uses the default output path (
lib/gen/) and creates an empty directory at the workspace root - Finds no assets to generate → produces no output
- 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_appapps/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
- Set up the workspace structure above
- Clean the build cache:
rm -rf .dart_tool/build- Run from the workspace root:
dart run build_runner build --workspace- Observe:
ls lib/gen/ # ← empty directory created at workspace root (default output path)
ls apps/my_app/lib/generated/ # ← expected output NOT generatedExpected behavior
flutter_gen_runnerreadsapps/my_app/pubspec.yamlfor themy_apppackage- Generates
apps/my_app/lib/generated/assets.gen.dart(per theflutter_gen.outputconfig) - Does NOT create anything at the workspace root
Actual behavior
flutter_gen_runnerreads the workspace rootpubspec.yaml(noflutter_gen:section)- Creates an empty
lib/gen/directory at the workspace root (default output path) - Does not generate
assets.gen.dartfor the package — build log showsno-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 buildRelevant a pubspec.yaml.
Relevant log output
Code of Conduct
- I agree to follow this project's Code of Conduct