# source_gen

> A framework for writing Dart code generators

Source: https://talira.ai/catalog/source-gen-mphgdz39
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Library
- Categories: [developer tools / code generation](https://talira.ai/categories/developer-tools/code-generation), [languages / dart](https://talira.ai/categories/languages/dart)
- Licence: BSD-3-Clause[^2]
- Pricing: Free and open source[^1]
- Free tier: yes[^1]
- Backed by: [Google](https://talira.ai/orgs/google.md)
- Funding: public company (NASDAQ:GOOGL)[^3]

source_gen is the Dart team's framework for writing Builders that read and produce Dart code, and the convention that lets hand-written and generated code, and several generators, live side by side in one project. You extend Generator or GeneratorForAnnotation, and source_gen calls it for a library or for each element tagged with your annotation. It wraps generators as a SharedPartBuilder (shared .g.dart part files, merged by its combining_builder), a PartBuilder or a LibraryBuilder, giving a friendlier API on top of the analyzer and build packages, and runs through [build_runner](https://talira.ai/catalog/build-runner-snjaeg1d.md) configured in build.yaml.

## Links

- GitHub: https://github.com/dart-lang/source_gen

## Problems it solves

- write a code generator for my Dart package
- generate Dart code from annotations in my source files
- let several code generators share one generated part file in a Dart project

## Features

- Generator and GeneratorForAnnotation base classes
- SharedPartBuilder, PartBuilder and LibraryBuilder for where generated code goes
- combining_builder that merges several generators' output into one .g.dart file
- configurable header and ignore_for_file lints for generated files

## Trust

Overall: 0.50 out of 1.
Signals: maintenance 0.63, adoption 0.54, momentum 0.20, community 0.68, backing 0.55, extensibility 0.00.

- last commit 9 days ago
- 4 commits in the last 90 days
- latest release source_gen-v4.3.1 46 days ago
- 492 GitHub stars
- 49 contributors
- backed by Google
- funding: public company (NASDAQ:GOOGL)

## Related

- Works with [build_runner](https://talira.ai/catalog/build-runner-snjaeg1d.md)

## Alternatives

- [code_builder](https://talira.ai/catalog/code-builder-bg87ba03.md): A fluent, builder-based library for generating valid Dart code
- [source_helper](https://talira.ai/catalog/source-helper-h09ez4h7.md): Utilities for generating Dart source code
- [json_serializable](https://talira.ai/catalog/json-serializable-3924m4hb.md): Generate JSON to and from code for annotated Dart classes
- [build_version](https://talira.ai/catalog/build-version-qkjxfdf5.md): Put your Dart package's version into your source code
- [copy_with_extension](https://talira.ai/catalog/copy-with-extension-perjthk3.md): Generates type-safe copyWith extensions for Dart classes

## Sources

[^1]: https://github.com/dart-lang/source_gen#readme (checked 28 Nov 2026)
[^2]: https://github.com/dart-lang/source_gen/blob/master/LICENSE (checked 28 Nov 2026)
[^3]: https://www.sec.gov/files/company_tickers_exchange.json (checked 20 Nov 2026)
