build
5.0.0, released 5 weeks ago by dart.dev
Package for authoring build_runner compatible code generators.
What it does
A package for writing code generators, called builders, that run with build_runner. It defines the core Builder interface and build step APIs for reading, analyzing, and writing files.
AI-written summary of version 5.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are developing a custom build_runner compatible code generator package.
- You need to implement the low-level Builder interface to generate code based on inputs.
Skip it when
- You are just writing a standard application or package that uses existing code generators rather than authoring one.
- You want a higher-level helper for annotation-based builders (use source_gen instead).
Strengths
- Provides the core underlying Builder interface used across the Dart build ecosystem.
- Gives easy access to the analyzer for processing and resolving Dart source code.
Weaknesses
- Low-level compared to source_gen, requiring more manual handling of build steps.
- Major version updates can introduce breaking changes for packages implementing BuildStep.
Setup
- Kind
- Pure Dart
- Effort
- Medium
- Code generation
- Yes (build_runner)
- Direct dependencies
- 6
Requires configuration with build_runner to run builders.
class CopyBuilder implements Builder {
@override
final buildExtensions = const {
'.txt': ['.txt.copy']
};
@override
Future<void> build(BuildStep buildStep) async {
final inputId = buildStep.inputId;
final outputId = inputId.addExtension('.copy');
final contents = await buildStep.readAsString(inputId);
await buildStep.writeAsString(outputId, contents);
}
}Alternatives
Packages that do the same job and could replace build.
- copy_with_extension
Annotation for generating copyWith extensions code using copy_with_extension_gen.
87Compare - json_annotation
Provides annotations for json_serializable to generate JSON (de)serialization code.
84Compare - widgetbook_annotation
Annotations for widgetbook_generator to build Flutter widgets in isolation.
80Compare - pigeon
Type-safe code generator for communication between Flutter and host platforms.
90Compare
Works with
Packages commonly used together with build: ones it builds on, ones built on it, and its own family.
- analyzerbuild depends on itPerforms static analysis of Dart code for tool integration and embedding.
- cryptobuild depends on itProvides SHA, MD5, and HMAC hashing functions for Dart.
- globbuild depends on itA file and directory globbing library that supports Bash-style path matching and listing.
- package_configbuild depends on itRead and write Dart package configuration files.
- loggingbuild depends on itProvides configurable logging with levels and stream listeners for Dart apps.
- hooksSame familyDart API for the JSON-based protocol for package build and link hooks.
- code_assetsSame familyProvides the hook protocol specification for bundling native code with Dart packages.
- testSame familyA full featured library for writing and running Dart tests across platforms.