fluttergitcicdworkspace

How to create local workspace in flutter such as go


My flutter project contains 4 or 5 packages from my own git and I do alter the code in packages too. I need to create a workspace to read the project from my local but only when I'm developing. I don't want to push the workspace to git so my ci/cd won't see the local packages but the git version. how is this possible with flutter. PS: I know I can comment out path and use git each time pushing the code but with a team of 5 it's hard to manage. Thanks in advance.


Solution

  • What you’re looking for is dependency overrides.

    Since you don’t want to edit pubspec.yaml directly, you can create a file named pubspec_overrides.yaml next to your pubspec.yaml. Anything declared there will override the corresponding entries in pubspec.yaml. If you add this file to .gitignore, it will only apply locally and won’t affect your repo or CI/CD.

    Whenever you run flutter pub get, Flutter automatically picks up and applies the overrides.


    Step 1: Define the "real" dependencies in pubspec.yaml

    dependencies:
      my_package:
        git:
          url: git@github.com:your-org/my_package.git
          ref: main
      another_package:
        git:
          url: git@github.com:your-org/another_package.git
          ref: main
    

    Step 2: Create pubspec_overrides.yaml for local development

    dependency_overrides: # Note: not "dependencies"
      my_package:
        path: ../local_workspace/my_package
      another_package:
        path: ../local_workspace/another_package
    

    Step 3: Ignore it in Git

    Add the file to your .gitignore:

    pubspec_overrides.yaml