source_gen
4.3.1, released 5 weeks ago by tools.dart.dev
Source code generation builders and utilities for the Dart build system.
What it does
Provides a framework for writing Dart code builders and a convention for human and tool-generated code to coexist. Exposes a developer-friendly API on top of the analyzer and build packages.
AI-written summary of version 4.3.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are writing custom code generators for Dart libraries or annotations
- You need to build custom Builders that consume and produce Dart code
Skip it when
- You are simply looking to use existing generators like json_serializable or freezed without writing your own
Strengths
- Exposes a developer-friendly API on top of lower-level analyzer and build packages
- Supports multiple code generators integrating seamlessly in the same project via shared part builders
Weaknesses
- Requires understanding of the Dart build system and analyzer APIs
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 9
Add source_gen to dependencies or dev_dependencies, and configure builders in a build.yaml file.
dependencies:
source_gen:
dev_dependencies:
build_runner:
build_config:Alternatives
Packages that do the same job and could replace source_gen.
- code_builder
A fluent, builder-based library for generating valid Dart code programmatically.
93Compare - lean_builder
Lean Builder: a fast, efficient Dart build system for code generation
73Compare - copy_with_extension
Annotation for generating copyWith extensions code using copy_with_extension_gen.
87Compare - build_version
Generate a Dart file with the package version at build time.
77Compare
Works with
Packages commonly used together with source_gen: ones it builds on, ones built on it, and its own family.
- analyzersource_gen depends on itPerforms static analysis of Dart code for tool integration and embedding.
- yamlsource_gen depends on itA Dart library for parsing YAML documents into Dart data structures.
- pub_semversource_gen depends on itVersions and version constraints implementing pub's versioning policy.
- globsource_gen depends on itA file and directory globbing library that supports Bash-style path matching and listing.
- dart_stylesource_gen depends on itProvides an API and CLI to format Dart source code automatically.
- asyncsource_gen depends on itUtility classes and helpers that extend Dart's async library.
- source_spansource_gen depends on itStandard representation for source code locations, spans, and human-friendly error messages.
- buildsource_gen depends on itPackage for authoring build_runner compatible code generators.