Skip to content

fix: Error while generating IntelliJ files with custom PUB_CACHE location #749

@alexisdelage

Description

@alexisdelage

Is there an existing issue for this?

  • I have searched the existing issues.

Version

6.1.0

Description

When the cache location for pub is different from $HOME/.pub-cache, the bootstrap command fails to generate IntelliJ files.
Using a custom cache location is needed for example on a GitLab CI, which does not allow to use built-in caching (to speed up the CI) outside of the project directory.

Steps to reproduce

  1. Define the PUB_CACHE env variable to a custom location (for example in your project): export PUB_CACHE=myproject/.pub-cache
  2. Activate melos: dart pub global activate melos
  3. Add melos to the PATH : export PATH="$PATH:$PUB_CACHE/bin"
  4. Bootstrap your project: melos bootstrap
  5. Melos successfully download packages but fails at generating IntelliJ files:
$ melos bootstrap
Resolving dependencies...
Downloading packages...
   [...]
Changed 8 dependencies!
39 packages have newer versions incompatible with dependency constraints.
Try `dart pub outdated` for more information.
melos bootstrap
  └> [...]
Running "flutter pub get" in workspace packages...
   [...]
  > SUCCESS
Generating IntelliJ IDE files...
Unhandled exception:
PathNotFoundException: Cannot open file, path = '/root/.pub-cache/hosted/pub.dev/melos-6.1.0/templates/intellij/modules/flutter_app_module.iml.tmpl' (OS Error: No such file or directory, errno = 2)
#0      _checkForErrorResponse (dart:io/common.dart:55:9)
#1      _File.open.<anonymous closure> (dart:io/file_impl.dart:[38](https://gitlab.com/atle2c/iot/atlantic_home_assist/-/jobs/7528595739#L38)1:7)
<asynchronous suspension>
#2      _File.readAsBytes.<anonymous closure> (dart:io/file_impl.dart:562:24)
<asynchronous suspension>
#3      _File.readAsString (dart:io/file_impl.dart:621:18)
<asynchronous suspension>
#4      Pool.withResource (package:pool/pool.dart:127:14)
<asynchronous suspension>
#5      IntellijProject.readFileTemplate (package:melos/src/common/intellij_project.dart:127:22)
<asynchronous suspension>
#6      IntellijProject.writePackageModule (package:melos/src/common/intellij_project.dart:179:22)
<asynchronous suspension>
#7      Future._kTrue (dart:async/future.dart:670:3)
<asynchronous suspension>
#8      _RootZone.bindUnaryCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1633:12)
<asynchronous suspension>

Expected behavior

I expect melos to follow the PUB_CACHE location to create the IntelliJ files.

Screenshots

No response

Additional context and comments

Disabling the IntelliJ files generation in the melos.yaml config file allows to fix the issue, but it is not the best solution as I use them for Android Studio.

My current fix: modifying the melos.yaml config directly in the CI to prevent IntelliJ files generation:

# gitlab-ci.yaml
default:
  image: ghcr.io/cirruslabs/flutter:stable
  cache:
    key:
      files:
        - ./**/pubspec.lock
    paths:
      - .pub-cache
  before_script:
    - export PUB_CACHE=$CI_PROJECT_DIR/.pub-cache
    - export PATH="$PATH:$PUB_CACHE/bin"
    - flutter pub global activate melos
    - "echo -e '\nide:\n  intellij:\n    enabled: false' >> melos.yaml"  # Disable IntelliJ IDE support
    - melos bootstrap

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtype: acceptedMarks issues/pull requests that are accepted & scheduled to be worked on.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions