Introduction
Managing multiple Flutter packages and apps in a single repository improves code sharing, testing speed, and deployment consistency in mobile development. Melos is a CLI tool purpose-built to orchestrate monorepos for Dart and Flutter: it bootstraps packages, runs scripts across workspaces, hoists dependencies, manages versions, and helps publish packages. This tutorial shows practical setup and common workflows to get Melos working reliably in Flutter monorepos.
Why Use Melos
Melos treats a repository as a workspace containing packages. For Flutter mobile development this gives immediate benefits:
Link local packages automatically (no manual path edits).
Run tasks in parallel across packages (tests, formatters, linters).
Centralize scripts and enforce consistent tooling versions.
Version bumping and publishing across related packages.
Better CI caching by bootstrapping once and running selective tasks.
If your team shares widgets, utilities, or plugins across apps, Melos reduces friction and accidental drift.
Setting Up Melos In A Flutter Monorepo
Install Melos either globally or as a dev dependency. Global install is convenient on developer machines and CI:
Create a melos.yaml at the repository root. Keep it minimal and explicit about your package layout. Example:
name: my_flutter_monorepo
packages:
- packages/*
- examples/*
scripts:
analyze:
run: dart analyze
format:
run: dart format .
test:
run
Place package folders under the directories you declared. Each package keeps its own pubspec.yaml. To wire up local dependencies and install transitive deps, run:
Bootstrap will run pub get for each package, create symlinks for local package references, and optionally hoist common dependencies to the root to speed up installs. After bootstrap, you can run any script defined in melos.yaml across packages with melos run.
If you prefer to pin Melos per repository, add it to a dev_dependency in a top-level tooling package and use dart run melos <command>.
Common Workflows And Commands
Key commands you'll use daily:
melos bootstrap — install and link local packages.
melos run <script> — run a named script from melos.yaml across matched packages.
melos exec -- <command> — execute a raw shell command in each package workspace.
melos version — manage version bumps across packages and generate changelogs.
melos publish — publish multiple packages in dependency order.
Examples:
Run analysis for all packages:
Run Flutter tests only in packages matching a filter:
Run a build script in parallel:
Scripts in melos.yaml can call Dart scripts inside packages. Example Dart script that could be invoked by a Melos script:
void main(List<String> args) {
final joined = args.isEmpty ? 'no args' : args.join(' ');
print('Package tool running with: $joined');
}Use melos list to view workspaces and melos run --no-concurrency when order or output clarity matters.
CI Integration And Best Practices
In CI, use melos to reduce install time and to run targeted tasks:
Cache the pub and melos build artifacts between runs.
Run melos bootstrap once and then melos run test or melos exec for per-package actions.
Use melos version in release pipelines to automate version and changelog generation.
For reproducible results, pin SDK constraints in pubspecs and use a single Melos version in the repo (commit melos.yaml and document the required Melos version).
Best practices:
Keep melos.yaml scripts idempotent and fast (format, analyze, test).
Use package filters (scope, ignore) to limit work during feature development.
Avoid hoisting Flutter SDK constraints; hoisting is for pub dependencies. Keep Flutter plugin and SDK versions explicit in package pubspecs.
Commit the generated melos.lock if you rely on deterministic hoisting or want to share exact resolved versions across developers.
Vibe Studio
Vibe Studio, powered by Steve’s advanced AI agents, is a revolutionary no-code, conversational platform that empowers users to quickly and efficiently create full-stack Flutter applications integrated seamlessly with Firebase backend services. Ideal for solo founders, startups, and agile engineering teams, Vibe Studio allows users to visually manage and deploy Flutter apps, greatly accelerating the development process. The intuitive conversational interface simplifies complex development tasks, making app creation accessible even for non-coders.
Conclusion
Melos turns a scattered Flutter monorepo into a predictable, automatable workspace. Use melos bootstrap to wire local packages, melos run and melos exec to orchestrate tasks, and melos version / melos publish for coordinated releases. With simple melos.yaml scripts and CI caching, teams can scale mobile development while maintaining consistent tooling and fast iteration.