felangel / mocktail

A mock library for Dart inspired by mockito
https://pub.dev/packages/mocktail
MIT License
617 stars 81 forks source link

Cannot install package `mocktail v0.3.0` with `build_runner 2.3.2` - version solving fails #164

Closed dorontal closed 1 year ago

dorontal commented 1 year ago

Describe the bug

it's not possible to use mocktail with build_runner - both current versions - seem to clash and version solving reports an error.

The current mocktail package v0.3.0 is not building when added to a new project.

When you run flutter pub get with mocktail having been just added, you get the following error:

--

[mocktail_test] flutter pub get
Running "flutter pub get" in mocktail_test...                    1,216ms
exit code 0

--

[mocktail_test] flutter pub get
Running "flutter pub get" in mocktail_test...                   
Because no versions of test match >1.21.4 <1.21.5 and test >=1.16.0-nullsafety.19 <1.16.6 depends on test_api 0.2.19, test >=1.16.0-nullsafety.19 <1.16.6-∞ or >1.21.4 <1.21.5-∞ requires test_api 0.2.19.
And because test >=1.16.6 <1.17.10 depends on analyzer ^1.0.0, test >=1.16.0-nullsafety.19 <1.17.10-∞ or >1.21.4 <1.21.5-∞ requires test_api 0.2.19 or analyzer ^1.0.0.
And because test >=1.17.10 <1.20.0 depends on analyzer >=1.0.0 <3.0.0 and test >=1.20.0 <1.21.2 depends on test_api 0.4.9, test >=1.16.0-nullsafety.19 <1.21.2-∞ or >1.21.4 <1.21.5-∞ requires test_api 0.2.19 or 0.4.9 or analyzer >=1.0.0 <3.0.0.
And because test >=1.21.2 <1.21.3 depends on test_api 0.4.10 and test >=1.21.3 <1.21.4 depends on test_api 0.4.11, test >=1.16.0-nullsafety.19 <1.21.4-∞ or >1.21.4 <1.21.5-∞ requires test_api 0.2.19 or 0.4.9 or 0.4.10 or 0.4.11 or analyzer >=1.0.0 <3.0.0.
And because test >=1.21.5 <1.21.6 depends on test_api 0.4.13 and test >=1.21.6 <1.21.7 depends on test_api 0.4.14, test >=1.16.0-nullsafety.19 <1.21.4-∞ or >1.21.4 <1.21.7-∞ requires test_api 0.2.19 or 0.4.9 or 0.4.10 or 0.4.11 or 0.4.13 or 0.4.14 or analyzer >=1.0.0 <3.0.0.
And because test >=1.21.7 <1.22.0 depends on test_api 0.4.15 and test >=1.22.0 depends on test_api 0.4.16, test >=1.16.0-nullsafety.19 <1.21.4-∞ or >1.21.4 requires test_api 0.2.19 or 0.4.9 or 0.4.10 or 0.4.11 or 0.4.13 or 0.4.14 or 0.4.15 or 0.4.16 or analyzer >=1.0.0 <3.0.0.
And because test 1.21.4 depends on test_core 0.4.16 which depends on frontend_server_client ^2.1.0, test >=1.16.0-nullsafety.19 requires test_api 0.2.19 or 0.4.9 or 0.4.10 or 0.4.11 or 0.4.13 or 0.4.14 or 0.4.15 or 0.4.16 or analyzer >=1.0.0 <3.0.0 or frontend_server_client ^2.1.0.
And because build_runner >=2.2.1 depends on analyzer >=4.4.0 <6.0.0 and every version of flutter_test from sdk depends on test_api 0.4.12, if flutter_test from sdk and test >=1.16.0-nullsafety.19 and build_runner >=2.2.1 then frontend_server_client ^2.1.0.
And because build_runner >=2.3.1 depends on frontend_server_client ^3.0.0 and mocktail 0.3.0 depends on test ^1.16.0, one of flutter_test from sdk or build_runner >=2.3.1 or mocktail 0.3.0 must be false.
And because no versions of mocktail match >0.3.0 <0.4.0 and mocktail_test depends on mocktail ^0.3.0, flutter_test from sdk is incompatible with build_runner >=2.3.1.
So, because mocktail_test depends on both build_runner ^2.3.2 and flutter_test from sdk, version solving failed.
pub get failed (1; So, because mocktail_test depends on both build_runner ^2.3.2 and flutter_test from sdk, version solving failed.)
exit code 1

To Reproduce Steps to reproduce the behavior:

  1. In VSCode, start a new flutter project
  2. Add mocktail to your pubspect.yaml's dev dependencies
  3. Add 'build_runner to your pubspect.yaml's dev dependencies`
  4. Run flutter pub get

When you run flutter pub get you will see the version solving error .

Expected behavior I expected flutter pub get to not fail.

Logs Run flutter analyze and attach any output of that command below.

dtal@thing4: flutter analyze
Analyzing lib...                                                
No issues found! (ran in 1.7s)

Paste the output of running flutter doctor -v here.

dtal@thing4: flutter doctor -v
[✓] Flutter (Channel stable, 3.3.7, on Debian GNU/Linux 11 (bullseye)
    5.10.0-18-amd64, locale en_US.UTF-8)
    • Flutter version 3.3.7 on channel stable at /home/dtal/local/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision e99c9c7cd9 (8 days ago), 2022-11-01 16:59:00 -0700
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version
    32.1.0-rc1)
    • Android SDK at /home/dtal/Android/Sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • Java binary at: /usr/local/src/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = chromium

[✓] Linux toolchain - develop for Linux desktop
    • Debian clang version 11.0.1-2
    • cmake version 3.18.4
    • ninja version 1.10.1
    • pkg-config version 0.29.2

[✓] Android Studio (version 2021.1)
    • Android Studio at /usr/local/src/android-studio
    • Flutter plugin version 66.0.1
    • Dart plugin version 211.7817
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)

[✓] VS Code (version 1.73.0)
    • VS Code at /usr/share/code
    • Flutter extension version 3.52.0

[✓] Connected device (3 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    •
      Android 8.0.0 (API 26) (emulator)
    • Linux (desktop)                    • linux         • linux-x64      •
      Debian GNU/Linux 11 (bullseye) 5.10.0-18-amd64
    • Chrome (web)                       • chrome        • web-javascript •
      Chromium 107.0.5304.87 built on Debian 11.5, running on Debian 11.5

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
felangel commented 1 year ago

Hi @dorontal 👋 Thanks for opening an issue!

I am not able to reproduce. The pubspec.yaml I have looks like:

name: example
description: A new Flutter project.
version: 1.0.0+1
publish_to: "none"

environment:
  sdk: ">=2.18.4 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

dev_dependencies:
  flutter_test:
    sdk: flutter
  mocktail: ^0.3.0

flutter:
  uses-material-design: true

And I'm able to run flutter packages get with no issues.

The generated lock file is:

# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
  _fe_analyzer_shared:
    dependency: transitive
    description:
      name: _fe_analyzer_shared
      url: "https://pub.dartlang.org"
    source: hosted
    version: "47.0.0"
  analyzer:
    dependency: transitive
    description:
      name: analyzer
      url: "https://pub.dartlang.org"
    source: hosted
    version: "4.7.0"
  args:
    dependency: transitive
    description:
      name: args
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.3.1"
  async:
    dependency: transitive
    description:
      name: async
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.9.0"
  boolean_selector:
    dependency: transitive
    description:
      name: boolean_selector
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.0"
  characters:
    dependency: transitive
    description:
      name: characters
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.2.1"
  clock:
    dependency: transitive
    description:
      name: clock
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.1.1"
  collection:
    dependency: transitive
    description:
      name: collection
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.16.0"
  convert:
    dependency: transitive
    description:
      name: convert
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.1.1"
  coverage:
    dependency: transitive
    description:
      name: coverage
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.6.1"
  crypto:
    dependency: transitive
    description:
      name: crypto
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.2"
  fake_async:
    dependency: transitive
    description:
      name: fake_async
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.3.1"
  file:
    dependency: transitive
    description:
      name: file
      url: "https://pub.dartlang.org"
    source: hosted
    version: "6.1.4"
  flutter:
    dependency: "direct main"
    description: flutter
    source: sdk
    version: "0.0.0"
  flutter_test:
    dependency: "direct dev"
    description: flutter
    source: sdk
    version: "0.0.0"
  frontend_server_client:
    dependency: transitive
    description:
      name: frontend_server_client
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.3"
  glob:
    dependency: transitive
    description:
      name: glob
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.0"
  http_multi_server:
    dependency: transitive
    description:
      name: http_multi_server
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.2.1"
  http_parser:
    dependency: transitive
    description:
      name: http_parser
      url: "https://pub.dartlang.org"
    source: hosted
    version: "4.0.2"
  io:
    dependency: transitive
    description:
      name: io
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.3"
  js:
    dependency: transitive
    description:
      name: js
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.6.5"
  logging:
    dependency: transitive
    description:
      name: logging
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.1.0"
  matcher:
    dependency: transitive
    description:
      name: matcher
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.12.12"
  material_color_utilities:
    dependency: transitive
    description:
      name: material_color_utilities
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.1.5"
  meta:
    dependency: transitive
    description:
      name: meta
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.8.0"
  mime:
    dependency: transitive
    description:
      name: mime
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.2"
  mocktail:
    dependency: "direct dev"
    description:
      name: mocktail
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.3.0"
  node_preamble:
    dependency: transitive
    description:
      name: node_preamble
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.1"
  package_config:
    dependency: transitive
    description:
      name: package_config
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.0"
  path:
    dependency: transitive
    description:
      name: path
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.8.2"
  pool:
    dependency: transitive
    description:
      name: pool
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.5.1"
  pub_semver:
    dependency: transitive
    description:
      name: pub_semver
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.2"
  shelf:
    dependency: transitive
    description:
      name: shelf
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.4.0"
  shelf_packages_handler:
    dependency: transitive
    description:
      name: shelf_packages_handler
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.1"
  shelf_static:
    dependency: transitive
    description:
      name: shelf_static
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.1.1"
  shelf_web_socket:
    dependency: transitive
    description:
      name: shelf_web_socket
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.3"
  sky_engine:
    dependency: transitive
    description: flutter
    source: sdk
    version: "0.0.99"
  source_map_stack_trace:
    dependency: transitive
    description:
      name: source_map_stack_trace
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.1"
  source_maps:
    dependency: transitive
    description:
      name: source_maps
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.10.11"
  source_span:
    dependency: transitive
    description:
      name: source_span
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.9.0"
  stack_trace:
    dependency: transitive
    description:
      name: stack_trace
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.10.0"
  stream_channel:
    dependency: transitive
    description:
      name: stream_channel
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.0"
  string_scanner:
    dependency: transitive
    description:
      name: string_scanner
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.1.1"
  term_glyph:
    dependency: transitive
    description:
      name: term_glyph
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.2.1"
  test:
    dependency: transitive
    description:
      name: test
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.21.4"
  test_api:
    dependency: transitive
    description:
      name: test_api
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.4.12"
  test_core:
    dependency: transitive
    description:
      name: test_core
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.4.16"
  typed_data:
    dependency: transitive
    description:
      name: typed_data
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.3.1"
  vector_math:
    dependency: transitive
    description:
      name: vector_math
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.2"
  vm_service:
    dependency: transitive
    description:
      name: vm_service
      url: "https://pub.dartlang.org"
    source: hosted
    version: "9.4.0"
  watcher:
    dependency: transitive
    description:
      name: watcher
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.0.2"
  web_socket_channel:
    dependency: transitive
    description:
      name: web_socket_channel
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.2.0"
  webkit_inspection_protocol:
    dependency: transitive
    description:
      name: webkit_inspection_protocol
      url: "https://pub.dartlang.org"
    source: hosted
    version: "1.2.0"
  yaml:
    dependency: transitive
    description:
      name: yaml
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.1.1"
sdks:
  dart: ">=2.18.4 <3.0.0"

Does the above pubspec.yaml not work for you as well?

dorontal commented 1 year ago

Hi @felangel, please accept my apologies for reporting less than I should have.

Originally I thought the conflict was with package build_runner - it is.

Try adding build_runner as a package - that's when I had the version solving failure.

dorontal commented 1 year ago

The pubspec.yaml for that test code (created by VSCode on new project, with manually added mocktail and build_runner) that failed version solving is (relevant excerpt):

dependencies:
  cupertino_icons: ^1.0.2
  flutter:
    sdk: flutter

dev_dependencies:
  build_runner: ^2.3.2
  flutter_lints: ^2.0.0
  flutter_test:
    sdk: flutter
  mocktail: ^0.3.0
dorontal commented 1 year ago

Here's a workaround: If you change the version of build_runner from ^2.3.2 to 2.2.1 version solving works and flutter pub get doesn't crash. The following dependency combo works:

dependencies:
  cupertino_icons: ^1.0.2
  flutter:
    sdk: flutter

dev_dependencies:
  build_runner: 2.2.1
  flutter_lints: ^2.0.0
  flutter_test:
    sdk: flutter
  mocktail: ^0.3.0
Sureya commented 1 year ago

I am also facing the same issue with the following dependecies. When I comment out mocktail, everything seems to work fine.

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^2.0.1
  mocktail: ^0.3.0
  build_runner: ^2.3.2
  freezed_annotation: ^2.2.0
  freezed: ^2.2.1
  hive_generator: ^2.0.0

Error message

Because test >=1.16.0-nullsafety.19 <1.16.6 depends on test_api 0.2.19 and test >=1.16.6 <1.17.10 depends on analyzer ^1.0.0, test >=1.16.0-nullsafety.19 <1.17.10 requires test_api 0.2.19 or analyzer ^1.0.0.
And because test >=1.17.10 <1.20.0 depends on analyzer >=1.0.0 <3.0.0 and test >=1.20.0 <1.21.2 depends on test_api 0.4.9, test >=1.16.0-nullsafety.19 <1.21.2 requires test_api 0.2.19 or 0.4.9 or analyzer >=1.0.0 <3.0.0.
And because test >=1.21.0 <1.21.6 depends on analyzer >=2.0.0 <5.0.0 and test >=1.21.6 <1.21.7 depends on test_api 0.4.14, test >=1.16.0-nullsafety.19 <1.21.7 requires test_api 0.2.19 or 0.4.9 or 0.4.14 or analyzer >=1.0.0 <5.0.0.
And because test >=1.21.7 <1.22.0 depends on test_api 0.4.15 and test >=1.22.0 depends on test_api 0.4.16, test >=1.16.0-nullsafety.19 requires test_api 0.2.19 or 0.4.9 or 0.4.14 or 0.4.15 or 0.4.16 or analyzer >=1.0.0 <5.0.0.
Because no versions of hive_generator match >2.0.0 <3.0.0 and hive_generator 2.0.0 depends on analyzer ^5.0.0, hive_generator ^2.0.0 requires analyzer ^5.0.0.
Thus, if hive_generator ^2.0.0 and test >=1.16.0-nullsafety.19 then test_api 0.2.19 or 0.4.9 or 0.4.14 or 0.4.15 or 0.4.16.
And because mocktail >=0.1.3 depends on test ^1.16.0, if hive_generator ^2.0.0 and mocktail >=0.1.3 then test_api 0.2.19 or 0.4.9 or 0.4.14 or 0.4.15 or 0.4.16.
And because $PROJECT depends on flutter_test from sdk which depends on test_api 0.4.12, hive_generator ^2.0.0 is incompatible with mocktail >=0.1.3.
So, because $PROJECT depends on both mocktail ^0.3.0 and hive_generator ^2.0.0, version solving failed.
pub get failed (1; So, because $PROJECT depends on both mocktail ^0.3.0 and hive_generator ^2.0.0, version solving failed.)
se1ya commented 1 year ago

Same problem for me. Fixed it with test_api dependency override like: dependency_overrides: test_api: 0.4.16

Here the stackoverflow answer

felangel commented 1 year ago

Unfortunately, it doesn't appear to be related to mocktail. The following pubspec.yaml has the same issue:

name: example
publish_to: none

environment:
  sdk: ">=2.18.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

dev_dependencies:
  build_runner: ^2.3.2
  flutter_test:
    sdk: flutter
  test: any

With build_runner 2.3.2 and flutter_test it's not possible to resolve any version of package:test (https://github.com/flutter/flutter/issues/115284)

felangel commented 1 year ago

Closing this as it appears to be fixed on the master channel of flutter.