Bootstrap Command
This command initializes the workspace and installs remaining package dependencies.
melos bootstrap
# or
melos bs
Bootstrapping has three primary functions:
- Installing all package dependencies (internally using
pub get). - Syncing shared dependencies between packages.
- Running any bootstrap lifecycle scripts.
Why is bootstrapping required?
After the Pub Workspaces feature was
introduced in Dart 3.6.0, it is no longer strictly necessary to run melos bootstrap, since all the packages are already linked together. However, there
are still some benefits to running melos bootstrap, if you for example want
to set up shared dependencies or attaching your own setup scripts to the
bootstrap hooks.
Benefits
Why would I want to use a monorepo?
- All local packages in the repository can be interlinked to point to their
local directories rather than 'remote' without pubspec.yaml modifications.
- Example Scenario: In a repository, package
Adepends on packageB. Both packagesA&Bexist in the monorepo. However, if youpub getinside packageA,pubwill retrieve packageBfrom the pub.dev registry as it's unaware ofBexisting locally. However, with Melos and pub workspaces, it's aware that packageBexists locally too, so it will generate the various pub files to point to a relative path in the local repository.- If you wanted to use pub you could of course define a dependency override
in the pubspec of package
Athat sets a path for packageBbut, then you'd have to do this manually every time and then manually remove it again when you want to publish or even commit your changes. This doesn't scale well and doesn't help with making a repository contributor friendly. FlutterFire for example has over 40 packages with various interlinking levels (try runmelos list --graphto see its local dependency graph).- This can also get phenomenally worse for example say if we introduce
package
Cthat packageBdepends on but packageCthen also depends onA.
- This can also get phenomenally worse for example say if we introduce
package
- If you wanted to use pub you could of course define a dependency override
in the pubspec of package
- Example Scenario: In a repository, package
- Interlinking highlights dart/analyzer issues early.
- Example Scenario: Package
Arelies on packageBfrom the same mono repo. PackageBgets a minor API change. Viapub geton packageAthe dart analyzer and IDEs report no issues with the package as it installed packageBfrom the remote pub registry and not local (which hasn't been published yet). With Melos, the dart analyzer / IDEs would highlight this issue immediately since local versions are used. The same applies for non-breaking deprecations, packageAwouldn't show there was a deprecated API in use without being interlinked through Melos.
- Example Scenario: Package
- Interlinking allows working on new, not yet published (or private) packages easily, without defining dependency overrides.
Combining with filters
Bootstrap supports all package filtering options, therefore if you wanted to you could bootstrap only a specific subset of your packages, for example:
# Only bootstrap packages that have
# changed since the main branch.
melos bootstrap --diff="main"
Bootstrap flags
- The
--no-exampleflag is used to exclude flutter package's example's dependencies (https://github.com/dart-lang/pub/pull/3856)- This will run
pub getwith the--no-exampleflag.
- This will run
- The
--enforce-lockfileflag is used to enforce versions from.lockfiles.- Ensure .lock files exist, as failure may occur if they're not checked in.
- The
--no-enforce-lockfileflag is used to disregard versions from.lockfiles ifenforce-lockfileis configured in the rootpubspec.yamlfile. - The
--offlineflag is used to only resolve dependencies from the local cache by runningpub getwith the--offlineflag.
In addition to the above flags, the melos bootstrap command supports a few
different configurations that can be defined in your root pubspec.yaml file.
Shared dependencies
If you want to share dependency versions between your packages in your Melos
project, just add the dependencies you wish to share between the packages to
your bootstrap config in your root pubspec.yaml file.
If a dependency from environment, dependencies or dev_dependencies in
your root pubspec.yaml exists in a package, the dependency version in this
package will be updated to match the version defined in your
bootstrap config every time melos bootstrap is run.
# root pubspec.yaml
# ...
melos:
command:
bootstrap:
environment:
sdk: ">=3.0.0 <4.0.0"
flutter: ">=3.0.0 <4.0.0"
dependencies:
collection: ^1.18.0
integral_isolates: any
uni_links2:
uni_links_macos:
git: https://github.com/SamJakob/uni_links_macos.git
dev_dependencies:
build_runner: ^2.3.3
# ...
Adding a post bootstrap lifecycle script
Melos supports various command lifecycle hooks
that can be defined in your root pubspec.yaml.
For example, if you needed to run something such as a build runner automatically
after melos bootstrap is run, you can add a post hook script:
# root pubspec.yaml
# ...
melos:
command:
bootstrap:
hooks:
post: dart pub run build_runner build
# ...
This is useful to ensure any local project requirements, such as generated files being built, are met when anyone is working on your mono repo code base, e.g. external contributors.

