简体   繁体   English

如何在 intellij idea 中以调试模式运行 flutter 'packages pub run build_runner build'?

[英]How run flutter 'packages pub run build_runner build' with debug mode in intellij idea?

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 and build_runner我使用source_genbuild_runner编写了生成器

class MyGenerator extends GeneratorForAnnotation<Todo> {
  @override
  FutureOr<String> generateForAnnotatedElement(
      Element element, ConstantReader annotation, BuildStep buildStep) {
    return "// Hey! Annotation found!";
  }
}
  1. run commad flutter packages pub run build_runner build运行命令flutter packages pub run build_runner build

  2. copy build.dart to root folder of projectbuild.dart复制到项目的根文件夹

在此处输入图像描述

3) 4) add new run configuration 3) 4) 添加新的运行配置在此处输入图像描述 5) run debug, now you can debug your code generator! 5)运行调试,现在你可以调试你的代码生成器了!

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.然后将构建脚本本身从build.dart重命名为build.dart.cached ,然后以代码 75 退出。

After digging through the build_runner code, I discovered that this behavior can be mitigated by using the following Program Arguments:在挖掘build_runner代码后,我发现可以通过使用以下程序 Arguments 来缓解这种行为:

serve --skip-build-script-check

(ie instead of just serve as Ivan suggested). (即不只是像伊万建议的那样serve )。

There may be some negative consequences;可能会有一些负面后果; in the build_runner source code, in options.dart , I saw this:build_runner源代码的options.dart中,我看到了这个:

// For testing only, skips the build script updates check.
bool skipBuildScriptCheck;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM