运行build_runner以使用Mockito包生成mock失败。
终端输出:
[INF]正在生成生成脚本。。。[INFO]正在生成生成脚本完成,耗时2.2s
[信息]正在预编译构建脚本。。。。。。[警告]/D:/floft_windows_1.22.5-stable/floft/.pub cache/hosts/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:42:19:错误:没有为类定义getter"libraryExports"LibraryElement"。
- "LibraryElement"来自"package:analyzer/dart/element/inelement.dart"('/D:/flutter_windows_1.22.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/analyzer-3.4.1/lib/dart/element/element.dart')。尝试将名称更正为现有getter的名称,或者定义名为"libraryExports"的getter或字段。…entryLib.libraryExports,^^^^^^^^^^^^^^/D:/flutter_windows_1.22.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:413:19:错误:没有为类定义getter"libraryImports"LibraryElement">
- "LibraryElement"来自"package:analyzer/dart/element/element.dart"('/D:/flutter_windows_1.22.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/analyzer-3.4.1/lib/dart/element/element.dart')。尝试将名称更正为现有getter的名称,或者定义名为"libraryImports"的getter或字段。…entryLib.libraryImports,^^^^^^^^^^^^^^/D:/flutter_windows_1.22.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:1493:36:错误:没有为类定义getter"enclosingElement2"ParameterElement">
- "ParameterElement"来自"package:analyzer/dart/element/element.dart"('/D:/flutter_windows_1.22.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/analyzer-3.4.1/lib/dart/element/element.dart')。尝试将名称更正为现有getter的名称,或者定义名为"enclosingElement2"的getter或字段。final方法=参数.conclosingElement2!;^^^^^^^^^^^^^^^^^/D:/flutter_windows_1.22.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:1524:30:错误:没有为类定义getter"enclosingElement2"ParameterElement">
- "ParameterElement"来自"package:analyzer/dart/element/element.dart"('/D:/flutter_windows_1.22.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/analyzer-3.4.1/lib/dart/element/element.dart')。尝试将名称更正为现有getter的名称,或者定义名为"enclosingElement2"的getter或字段。final方法=parameter.enclosingElement2作为MethodElement;^^^^^^^^^^^^^^^^^/D:/flutter_windows_1.22.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:1525:27:错误:没有为类定义getter"enclosingElement2"MethodElement">
- "MethodElement"来自"package:analyzer/dart/element/element.dart"('/D:/flutter_windows_1.22.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/analyzer-3.4.1/lib/dart/element/element.dart')。尝试将名称更正为现有getter的名称,或者定义名为"enclosingElement2"的getter或字段。final class_=method.enclosingElement2作为ClassElement;^^^^^^^^^^^^^^^^^/D:/flutter_windows_1.22.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:1535:28:错误:没有为类定义getter"enclosingElement2"'可执行元素'
- "ExecutableElement"来自"package:analyzer/dart/element/element.dart"('/D:/flutter_windows_1.22.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/analyzer-3.4.1/lib/dart/element/element.dart')。尝试将名称更正为现有getter的名称,或者定义名为"enclosingElement2"的getter或字段。overriddenMethod.enclosingElement2作为ClassElement,name);^^^^^^^^^^^^^^^^^/D:/flutter_windows_1.22.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:1934:23:错误:没有为类定义getter"enclosingElement2"'元素'
- "Element"来自"package:analyzer/dart/Element/Element.dart"("/D:/flutter_windows_122.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/analyzer-3.4.1/lib/dart/Element/Element.dart")。尝试将名称更正为现有getter的名称,或者定义名为"enclosingElement2"的getter或字段。var className=enclosingElement2!。名称^^^^^^^^^^^^^^^^^/D:/flutter_windows_1.22.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:1937:23:错误:没有为类定义getter"enclosingElement2"'元素'
- "Element"来自"package:analyzer/dart/Element/Element.dart"("/D:/flutter_windows_122.5-stable/flutter/.pub cache/hosts/pub.dartlang.org/analyzer-3.4.1/lib/dart/Element/Element.dart")。尝试将名称更正为现有getter的名称,或者定义名为"enclosingElement2"的getter或字段。var className=enclosingElement2!。名称^^^^^^^^^^^^^^^^^[信息]正在预编译生成脚本。。。完成,耗时22.4s
[SERVERE]无法预编译生成脚本.dart_tool/build/entrypoint/build.dart。这可能是由错误配置的生成器定义。
我曾尝试将分析器依赖项重写为1.5.0,但这会导致与项目中的其他依赖项发生冲突。
正在运行的颤振医生在终端中显示相同的错误。
这与升级到mockito v.3.0有关,dart pub upgrade
可能会解决它。如果没有,请将mockito版本恢复到5.2.0,它应该可以工作。
不带^
的mockito: 5.2.0
该问题是由analyzer
包引起的,它被用作mockito
的依赖项。
新版本4.4.0
似乎否决了一些API。
我目前所做的修复工作(直到维护人员在包中修复它)是将analyzer
作为最新稳定版本4.3.1
的pubspec.yaml
的依赖项,现在它就可以工作了。
dev_dependencies:
analyzer: 4.3.1
希望这能帮助