如何在IntelliJ IDEA中使用调试模式运行Flutter'packages pub run build_runner build'?

时间:2019-10-30 15:09:57

标签: intellij-idea flutter dart build-runner

我想在生成器代码上放置断点,但是我不知道如何在调试模式下运行命令。

我使用source_genbuild_runner

编写了生成器
class MyGenerator extends GeneratorForAnnotation<Todo> {
  @override
  FutureOr<String> generateForAnnotatedElement(
      Element element, ConstantReader annotation, BuildStep buildStep) {
    return "// Hey! Annotation found!";
  }
}

2 个答案:

答案 0 :(得分:3)

1)运行逗号@Override protected void onDestroy() { /// do smthng super.onDestroy(); }

2)将flutter packages pub run build_runner build复制到项目的根文件夹

enter image description here

3) 4)添加新的运行配置 enter image description here 5)运行调试,现在可以调试代码生成器了!

答案 1 :(得分:0)

Ivan 的回答对我有用,但是每次我更改使用注释的文件时 - 输出的构建过程:

[SEVERE] Terminating builds due to build script update
[INFO] Terminating. No further builds will be scheduled

然后将构建脚本本身从 build.dart 重命名为 build.dart.cached,然后以代码 75 退出。

在深入研究 build_runner 代码后,我发现可以通过使用以下程序参数来缓解这种行为:

serve --skip-build-script-check

(即,而不是像伊万建议的那样只是 serve)。

可能会有一些负面的后果;在 build_runner 源代码中,在 options.dart 中,我看到了:

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