Flutter: Sharing Dependencies in a Flutter Monorepo

Pavel Sulimau
ITNEXT
Published in
2 min readFeb 12, 2024

--

I believe many Dart & Flutter monorepo projects are already using Melos. It’s a useful tool for managing multiple packages, and I’m glad to see it continually improving.

Shared Dependencies Feature

In this article, I am eager to shine a spotlight on the Shared Dependencies feature that was introduced in Melos 3.2.0.

Essentially, if you want to share a dependency version between the packages in your monorepo, just add the dependency to the melos.yaml file, and melos bootstrap command will make sure your pubscpec.yamlfiles are updated accordingly to match the version defined in the melos.yaml file. It works not only for dependencies or dev_dependencies but for environment configuration as well.

More context about it can be gained from its feature request and the PR where it was implemented.

Shared Dependencies In Practice

Let’s see how it works in practice using the Flame project as an example.
At the moment of writing a bunch of packages from the Flame monorepo depend on meta v1.9.1, you can see the copied bootstrap configuration below.

After I update the meta version to meta: ^1.10.0 in the melos.yaml and run the melos bs command, I get 49 packages bootstrapped, 9 of them that depend on meta got the very same update right away! That’s quite handy and may ease the dependencies management in Dart/Flutter monorepos.

Conclusion

While it’s true that package management in the Dart/Flutter ecosystem is less mature compared to other platforms like .NET, we are fortunate to have tools like Melos at our disposal that can simplify the process. By actively contributing to such tools, we can play a role in improving the developer experience and fostering greater satisfaction within the community.

Resources

--

--