Running build_runner to generate mocks using the Mockito package fails.
Terminal output:
[INFO] Generating build script... [INFO] Generating build script completed, took 2.2s
[INFO] Precompiling build script...... [WARNING] /D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:412:19: Error: The getter 'libraryExports' isn't defined for the class 'LibraryElement'.
- 'LibraryElement' is from 'package:analyzer/dart/element/element.dart' ('/D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-3.4.1/lib/dart/element/element.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'libraryExports'. ...entryLib.libraryExports, ^^^^^^^^^^^^^^ /D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:413:19: Error: The getter 'libraryImports' isn't defined for the class 'LibraryElement'.
- 'LibraryElement' is from 'package:analyzer/dart/element/element.dart' ('/D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-3.4.1/lib/dart/element/element.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'libraryImports'. ...entryLib.libraryImports, ^^^^^^^^^^^^^^ /D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:1493:36: Error: The getter 'enclosingElement2' isn't defined for the class 'ParameterElement'.
- 'ParameterElement' is from 'package:analyzer/dart/element/element.dart' ('/D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-3.4.1/lib/dart/element/element.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'enclosingElement2'. final method = parameter.enclosingElement2!; ^^^^^^^^^^^^^^^^^ /D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:1524:30: Error: The getter 'enclosingElement2' isn't defined for the class 'ParameterElement'.
- 'ParameterElement' is from 'package:analyzer/dart/element/element.dart' ('/D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-3.4.1/lib/dart/element/element.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'enclosingElement2'. final method = parameter.enclosingElement2 as MethodElement; ^^^^^^^^^^^^^^^^^ /D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:1525:27: Error: The getter 'enclosingElement2' isn't defined for the class 'MethodElement'.
- 'MethodElement' is from 'package:analyzer/dart/element/element.dart' ('/D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-3.4.1/lib/dart/element/element.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'enclosingElement2'. final class_ = method.enclosingElement2 as ClassElement; ^^^^^^^^^^^^^^^^^ /D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:1535:28: Error: The getter 'enclosingElement2' isn't defined for the class 'ExecutableElement'.
- 'ExecutableElement' is from 'package:analyzer/dart/element/element.dart' ('/D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-3.4.1/lib/dart/element/element.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'enclosingElement2'. overriddenMethod.enclosingElement2 as ClassElement, name); ^^^^^^^^^^^^^^^^^ /D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:1934:23: Error: The getter 'enclosingElement2' isn't defined for the class 'Element'.
- 'Element' is from 'package:analyzer/dart/element/element.dart' ('/D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-3.4.1/lib/dart/element/element.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'enclosingElement2'. var className = enclosingElement2!.name; ^^^^^^^^^^^^^^^^^ /D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/mockito-5.3.0/lib/src/builder.dart:1937:23: Error: The getter 'enclosingElement2' isn't defined for the class 'Element'.
- 'Element' is from 'package:analyzer/dart/element/element.dart' ('/D:/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-3.4.1/lib/dart/element/element.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'enclosingElement2'. var className = enclosingElement2!.name; ^^^^^^^^^^^^^^^^^ [INFO] Precompiling build script... completed, took 22.4s
[SEVERE] Failed to precompile build script .dart_tool/build/entrypoint/build.dart. This is likely caused by a misconfigured builder definition.
I have tried overriding the analyzer dependency to 1.5.0 but it causes conflicts with other dependencies in the project.
Running flutter doctor shows the same errors in the terminal.
CodePudding user response:
This is related to upgrading to mockito v5.3.0, dart pub upgrade
might solve it. if not, revert mockito version to 5.2.0 and it should work.
CodePudding user response:
The issue is caused by analyzer
package, that it's used as a dependency for mockito
.
Seems like the new version 4.4.0
deprecated a few APIs.
What I did to fix it for now (until maintainers fix it on the package) is to include analyzer
as a dependency on my pubspec.yaml
with latest stable version 4.3.1
and it works now.
dev_dependencies:
analyzer: 4.3.1
Hope this helps