【问题标题】:How run flutter 'packages pub run build_runner build' with debug mode in intellij idea?如何在 intellij idea 中使用调试模式运行颤振“packages pub run build_runner build”?
【发布时间】:2020-02-25 22:22:55
【问题描述】:

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

我使用source_genbuild_runner 编写了生成器

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

【问题讨论】:

    标签: intellij-idea flutter dart build-runner


    【解决方案1】:
    1. 运行逗号flutter packages pub run build_runner build

    2. 复制build.dart到项目根目录

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

    【讨论】:

    • 谢谢!不过请注意,请确保您的“工作目录”指向“pubspec.yaml”所在的flutter项目的根路径。
    【解决方案2】:

    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
    

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-14
      • 1970-01-01
      • 2022-10-08
      • 2022-11-16
      • 1970-01-01
      • 2021-12-02
      • 1970-01-01
      • 2016-01-29
      相关资源
      最近更新 更多