Skill v1.0.1
currentAutomated scan100/100+7 new
name: flutter-melos-workspace description: "Apply Melos to Flutter/Dart monorepo projects for workspace orchestration, shared scripts, dependency management, versioning, and CI automation. Use when setting up Melos from scratch, adding/removing packages, defining custom scripts, configuring filters, managing versioning/changelogs, or troubleshooting workspace-level build/test/analyze workflows." user-invocable: true metadata: version: "1.0.1"
Flutter Melos Workspace
Runtime and resources
Use the current agent's native file, search, shell, and question tools; plain-text questions and direct sequential scans are valid fallbacks. Subagents are optional and require host permission. Bundled paths below are relative to this installed skill directory; application paths are relative to the target Flutter project. Resolve sibling skills through the installed skill registry (or sibling directories), never by assuming a skills/ folder in the application. If a required dependency is absent, name it and report the affected step as unavailable; never invent its rules or claim complete coverage.
Overview
Melos is a CLI tool for managing Dart/Flutter monorepos with multiple packages. It orchestrates dependency resolution, script execution, versioning, and changelogs across the workspace.
This skill covers Melos v3+ (latest stable) and Melos v6+/v7+ (with Pub workspace support).
When to use
- Setting up Melos in an existing or new monorepo.
- Adding/removing packages from the workspace.
- Defining shared scripts (analyze, test, build, format, codegen).
- Configuring package filters and scoping.
- Managing versioning and changelogs (conventional commits).
- CI/CD pipeline integration with Melos.
- Migrating from manual workspace management to Melos.
Setup workflow
1. Install Melos
dart pub global activate melos
Or add as dev dependency in root pubspec.yaml:
dev_dependencies:melos: ^7.0.0
2. Configuration file
Melos can be configured in two ways:
- Standalone `melos.yaml` at repo root (traditional, recommended for visibility).
- Inline `melos:` key in root
pubspec.yaml(compact, used when Pub workspace is also declared).
3. Minimal configuration
name: my_workspacepackages:- apps/*- packages/*
4. Bootstrap
melos bootstrap# or shorthand:melos bs
This links local packages and resolves dependencies across the workspace.
With Pub workspaces (Dart 3.5+ / Melos 7+): If the root pubspec.yaml declares a workspace: key, dart pub get at root already resolves shared dependencies. Melos bootstrap adds linking and script orchestration on top.
Configuration reference
Package filters
Melos commands accept filters to scope execution:
melos run test --scope="gap_core" # by namemelos run test --ignore="*_demo_*" # exclude patternmelos run test --dir-exists="test" # only packages with test/ dirmelos run test --depends-on="flutter" # only packages depending on fluttermelos run test --no-private # exclude private packagesmelos run test --since="main" # only changed since branch
Scripts
Define reusable commands in melos.yaml (or under melos: in pubspec.yaml):
scripts:analyze:run: dart analyze --fatal-infosdescription: Run static analysis on all packagespackageFilters:dirExists: libtest:run: flutter testdescription: Run tests in all packagespackageFilters:dirExists: testtest:selective:run: flutter testdescription: Run tests only in changed packagespackageFilters:dirExists: testsince: mainformat:run: dart format --set-exit-if-changed .description: Check formattingcodegen:run: dart run build_runner build --delete-conflicting-outputsdescription: Run code generationpackageFilters:dependsOn: build_runnerclean:run: flutter cleandescription: Clean all packagesdeps:graph:run: melos list --graphdescription: Show dependency graphdeps:outdated:run: dart pub outdateddescription: Check outdated dependencies
Script execution modes
- `exec`: Runs the command in each package directory (default for
run). - `run`: Runs a single command at workspace root.
- `packageFilters`: Scopes which packages the script applies to.
- `env`: Inject environment variables.
- `failFast`: Stop on first failure (default: true).
- `concurrency`: Max parallel executions.
Example with exec and concurrency:
scripts:test:exec: flutter testconcurrency: 4packageFilters:dirExists: test
Versioning and changelogs
Melos supports automated versioning via conventional commits:
command:version:message: "chore(release): publish %v"includeCommitId: truelinkToCommits: trueworkspaceChangelog: trueupdateGitTagRefs: truebranch: mainbootstrap:usePubspecOverrides: true
Workflow:
melos version # bump versions based on conventional commitsmelos version --prerelease # pre-release bumpmelos version --graduate # graduate pre-release to stable
IDE integration
Generate IDE configuration for local package resolution:
ide:intellij:enabled: true
Pub workspace + Melos coexistence (Dart 3.5+)
Modern Dart supports native workspace: in pubspec.yaml. This provides shared resolution without Melos. When combining both:
- Root
pubspec.yamldeclaresworkspace:listing all packages. - Melos adds orchestration (scripts, filters, versioning) on top.
melos bootstrapstill works and respects the Pub workspace resolution.- Individual packages use
resolution: workspacein theirpubspec.yaml.
# Root pubspec.yamlname: my_workspaceenvironment:sdk: ^3.5.0workspace:- apps/app_one- apps/app_two- packages/shared_coredev_dependencies:melos: ^7.0.0melos:name: my_workspacepackages:- apps/*- packages/*scripts:# ... scripts here
Migration checklist (manual workspace -> Melos)
- Ensure all packages are listed in
packages:glob patterns. - Run
melos bootstrapand verify all packages link correctly. - Replace any manual
flutter pub getloops withmelos bs. - Move repeated script patterns (analyze, test, format) to
scripts:. - Add
packageFiltersto scope scripts appropriately. - If using conventional commits, configure
command.version. - Update CI to use
melos bootstrap+melos run <script>. - Verify
melos listshows all expected packages. - Verify
melos run analyzeandmelos run testpass.
Common patterns
Run only affected packages in CI
scripts:ci:test:exec: flutter testpackageFilters:dirExists: testsince: origin/main
Pre-commit hook integration
melos run format && melos run analyze
Build runner across workspace
scripts:codegen:exec: dart run build_runner build --delete-conflicting-outputspackageFilters:dependsOn: build_runnerconcurrency: 1 # avoid file lock conflicts
Custom environment variables
scripts:build:apk:run: flutter build apk --releaseenv:FLUTTER_BUILD_NUMBER: ${MELOS_PACKAGE_VERSION}
Troubleshooting
- "Package not found" after adding new package: Re-run
melos bootstrap. - Circular dependency detected: Check
melos list --graphand break the cycle. - Script not running in expected packages: Add
--verboseflag or checkpackageFilters. - Version conflicts: With Pub workspace, ensure
resolution: workspacein child packages. - Bootstrap fails on CI: Ensure
melosis activated globally or usedart pub global run melos bootstrap.