How run flutter 'packages pub run build_runner build' with debug mode in intellij idea?
Solution 1
-
run commad
flutter packages pub run build_runner build
* -
copy
build.dart
to root folder of project
* the packages
is optional, you can just run flutter pub run build_runner build
Solution 2
Ivan's answer worked for me, but every time I changed a file that was using an annotation - the build process outputted:
[SEVERE] Terminating builds due to build script update
[INFO] Terminating. No further builds will be scheduled
and then renamed the build script itself from build.dart
to build.dart.cached
, and then exit with code 75.
After digging through the build_runner
code, I discovered that this behavior can be mitigated by using the following Program Arguments:
serve --skip-build-script-check
(i.e. instead of just serve
as Ivan suggested).
There may be some negative consequences; in the build_runner
source code, in options.dart
, I saw this:
// For testing only, skips the build script updates check.
bool skipBuildScriptCheck;
Ivan
Updated on December 15, 2022Comments
-
Ivan over 1 year
I want to put break point on my generator code, but I don't know how to run the command on the debug mode.
I wrote generator using
source_gen
andbuild_runner
class MyGenerator extends GeneratorForAnnotation<Todo> { @override FutureOr<String> generateForAnnotatedElement( Element element, ConstantReader annotation, BuildStep buildStep) { return "// Hey! Annotation found!"; } }
-
mitch2na over 3 yearsThanks for this! Just a side note though, make sure your "Working directory" points to the root path of flutter project where "pubspec.yaml" is located.
-
Ben Butterworth about 2 yearsYou don't actually have to copy the file to the root of the project. Just open the file in Android Studio and place a breakpoint in it. Then debug the project as a Dart Command Line App with
Dart file
set to the path of the file, eg/opt/flutter/.pub-cache/hosted/pub.dartlang.org/build_runner-2.1.7/lib/src/entrypoint/build.dart
. You can copy Absolute Path using the Android Studio project tab