NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
pub.dev · #144 most downloaded on pub.dev
Source code generation builders and utilities for the Dart build system
Last release 1 months ago
19 Aug 2026
Release timing varies
gaps range from 2 weeks to 6 months
Nearly every release is documented
notes for 60 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
12 years old
146 releases · first in 2015
Support the latest pkg:analyzer.
pkg:analyzer.The result of ConstantReader.revive() now returns a Revivable that assumes access to a private class, constructor, or function _instead_ of null where
The result of ConstantReader.revive() now returns a Revivable that assumes
access to a private class, constructor, or function instead of null where
possible. This allows generators that use part files to still use this
functionality and allows generators that use separate libraries to emit more
actionable error messages (i.e. "cannot use private class _X").
Revivable.isPrivate now returns true when the underlying class was public
but the constructor was private, or the Revivable was pointing to a
top-level or static private field or method. Previously it was only true
when referencing a private class.
One column per quarter.
Fix LibraryReader.classElements to return classes from parts, if they exist, as well as from the defining library file.
LibraryReader.classElements to return classes from parts, if they exist,
as well as from the defining library file.Introduce SharedPartBuilder for creating part files that can be merged with a new CombiningBuilder. Note that CombiningBuilder only outputs .g.dart fi
SharedPartBuilder for creating part files that can be merged
with a new CombiningBuilder. Note that CombiningBuilder only outputs
.g.dart files.PartBuilder now requires a generatedExtensions argument. The
value should not be .g.dart. To produce .g.dart files please use the
SharedPartBuilder.Allow using non-dev Dart 2 SDK.
generateForAnnotatedElement now allow multiple return values when implementations return an Iterable or Stream.
GeneratorForAnnotation
generateForAnnotatedElement now allow multiple return values when
implementations return an Iterable or Stream.generateForAnnotatedElement have whitespace trimmed. null
and empty values are ignored.Simplification to the output of generator names in header sections.
Simplification to the output of generator names in header sections.
Update handling of whitespace in generator outputs.
Support package:analyzer 0.32.0.
package:analyzer 0.32.0.Eliminate redundant new lines in the core builder. These were almost removed by running the default formatter. Now the unformatted code more closely m
More redundant new lines elimination.
Cleanup logging output that duplicates headers provided by package:build_runner.
Cleanup logging output that duplicates headers provided by
package:build_runner.
InvalidGenerationSourceError added an optional element
parameter to support more helpful error messages.
BREAKING removed the deprecated requireLibraryDirective parameter in PartBuilder.
BREAKING removed the deprecated requireLibraryDirective parameter in
PartBuilder.
Revivable no longer throws a type error when attempting to revive a
reference to a top-level function or static-class method. Now is returns a
reference to that function or method, as expected.
TypeChecker now throws an UnresolvedAnnotationException with a more detailed exception body (and properties useful for further debugging) instead of C
TypeChecker now throws an UnresolvedAnnotationException with a more
detailed exception body (and properties useful for further debugging) instead
of Could not resolve @null.LibraryBuilder and PartBuilder now have a more readable toString(), which is useful when emitting a warning or error in a build system. For example yo
LibraryBuilder and PartBuilder now have a more readable toString(),
which is useful when emitting a warning or error in a build system. For
example you may see Generating .g.dart: MyBuilder instead of
Instance of LibraryBuilder in your build logs.The PartBuilder constructor parameter requireLibraryDirective now defaults to false. It will be removed in 0.8.0.
The PartBuilder constructor parameter requireLibraryDirective now defaults
to false. It will be removed in 0.8.0.
Require at least Dart 2.0.0-dev.19.0.
Removed a log.finest with the output source of each generator. This allows a verbose option (-v) for tools like bazel or build_runner to be much more
log.finest with the output source of each generator. This allows
a verbose option (-v) for tools like bazel or build_runner to be much more
readable and debuggable. Files are emitted to disk for inspection in any
case.BUG FIX: ConstantReader.revive() now properly returns no URL fragment when the constant expression is resolved from a top-level or static-field. The d
BUG FIX: ConstantReader.revive() now properly returns no URL fragment
when the constant expression is resolved from a top-level or static-field.
The documentation had said otherwise, and it was impossible to tell the
difference between a constructor and a field. Now, fields are always in
the form of accessor = {clazz}.{field} or {topLevelField}.
Fix file URIs on windows.
Support the latest analyzer package.
analyzer package.Added typeNameOf, which is a safe way to get the name of a DartType, even when the type is a FunctionType, which has a null name in newer versions of
Added typeNameOf, which is a safe way to get the name of a DartType,
even when the type is a FunctionType, which has a null name in newer
versions of the Dart analyzer.
Added LibraryReader.pathToUrl(Uri|String), which computes the import or
export path necessary to reach the provided URL from the current library.
Also added pathToAsset and pathToElement as convenience functions.
Expanded package:build support to allow version 0.12.0.
Allow null and empty outputs form GeneratorForAnnotation.
GeneratorForAnnotation.Allow package:build version 0.11.0
package:build version 0.11.0Support an optional header argument to PartBuilder and LibraryBuilder.
header argument to PartBuilder and LibraryBuilder.Added isAny (for consistency, but _deprecated_) and isLiteral.
Generator{ForAnnotation}generate{ForAnnotatedElement} is now FutureOr<String>.LibraryReaderannotatedElements to return all elements annotated with something.classElements getter for returning all class-es in a library.TypeCheckerhasAnnotationOf and hasAnnotationOfExact.ConstantReaderisAny (for consistency, but deprecated) and isLiteral.literalValue as an alias for the now deprecated anyValue.literalValue to return null if the value is actually null.Symbol would return as a String for anyValue.List and Map were not considered literals.Breaking changes: See the wiki for help upgrading.
Breaking changes: See the wiki for help upgrading.
Generator.generate now operates on a LibraryReader rather than being
called for every Element within a library. Generators can iterate over
elements using LibraryReader.allElements. GeneratorForAnnotation will
continue to call generateForAnnotatedElement repeatedly for each element.GeneratorForAnnotation passes in a ConstantReader for the annotation
instance rather than re-creating it using mirrors.GeneratorBuilder is replaced with PartBuilder and LibraryBuilder
depending on whether the output is meant to be included in a part file.JsonSerializable and related classes. These are moved to
package:json_serializable.lib/builder.dart. Import through source_gen.dart instead.OutputFormatter typedef.Add LibraryReader.allElements - a utility to iterate across all Element
instances contained in Dart library.
Add LibraryReader.element to get back to the LibraryElement instance.
Add ConstantReader.objectValue to get back to the DartObject instance.
Add ConstantReader.peek to read a value that returns null if not found:
// Tries to read the field "token" first, then "_token".
findTokenField(DartObject o) {
final reader = new ConstantReader(o);
final token = o.peek('token') ?? o.read('_token');
}
throwOnUnresolved optional parameter to TypeChecker.annotationsOf,
TypeChecker.annotationsOfExact, TypeChecker.firstAnnotationOf, and
TypeChecker.firstAnnotationOfExact. Setting this to false will enable you
to check for matching annotations with incomplete type information (at your
own risk).AssetId instead of the library,
which is more useful for tracking down the actual files.Added spanForElement; returns a SourceSpan for an analyzer Element.
spanForElement; returns a SourceSpan for an analyzer Element.GeneratorBuilder outputs a part file
for a given input, but that input does not define part 'name.g.dart';.Tighten constraint on source_span.
source_span.Breaking change: TypeChecker#annotationsOf|firstAnnotationOf now returns annotations that are _assignable_ to the TypeChecker's type. As a result we'v…
TypeChecker#annotationsOf|firstAnnotationOf now
returns annotations that are assignable to the TypeChecker's type. As a
result we've added #annotationsOfExact|firstAnnotationOfExact which has the
old behavior for precise checks.TypeChecker#annotations...-methods now throw a StateError if one or more
annotations on an element are not resolvable. This is usually a sign of a
misspelling, missing import, or missing dependency.TypeChecker.any, which delegates to multiple other TypeChecker
implementations when making a type check.Do not fail when "library" is omitted but nothing would be output.
Update minimum analyzer package to 0.29.10.
analyzer package to 0.29.10.Deprecated builder.dart: import source_gen.dart instead.
Update the minimum Dart SDK to 1.22.1.
Deprecated builder.dart: import source_gen.dart instead.
Added TypeChecker, a high-level API for performing static type checks:
import 'package:analyzer/dart/element/type.dart';
import 'package:source_gen/source_gen.dart';
void checkType(DartType dartType) {
// Checks compared to runtime type `SomeClass`.
print(const TypeChecker.forRuntime(SomeClass).isExactlyType(dartType));
// Checks compared to a known Url/Symbol:
const TypeChecker.forUrl('package:foo/foo.dart#SomeClass');
// Checks compared to another resolved `DartType`:
const TypeChecker.forStatic(anotherDartType);
}
Failing to add a library directive to a library that is being used as a
generator target that generates partial files (part of) is now an explicit
error that gives a hint on how to name and fix your library:
> Could not find library identifier so a "part of" cannot be built.
>
> Consider adding the following to your source file:
>
> "library foo.bar;"
In Dart SDK >=1.25.0 this can be relaxed as part of can refer to a path.
To opt-in, GeneratorBuilder now has a new flag, requireLibraryDirective.
Set it to false, and also set your sdk constraint appropriately:
sdk: '>=1.25.0 <2.0.0'
Added LibraryReader, a utility class for LibraryElement that exposes
high-level APIs, including findType, which traverses export directives
for publicly exported types. For example, to find Generator from
package:source_gen/source_gen.dart:
void example(LibraryElement pkgSourceGen) {
var library = new LibraryReader(pkgSourceGen);
// Instead of pkgSourceGen.getType('Generator'), which is null.
library.findType('Generator');
}
Added ConstantReader, a high-level API for reading from constant (static)
values from Dart source code (usually represented by DartObject from the
analyzer package):
abstract class ConstantReader {
factory ConstantReader(DartObject object) => ...
// Other methods and properties also exist.
/// Reads[ field] from the constant as another constant value.
ConstantReader read(String field);
/// Reads [field] from the constant as a boolean.
///
/// If the resulting value is `null`, uses [defaultTo] if defined.
bool readBool(String field, {bool defaultTo()});
/// Reads [field] from the constant as an int.
///
/// If the resulting value is `null`, uses [defaultTo] if defined.
int readInt(String field, {int defaultTo()});
/// Reads [field] from the constant as a string.
///
/// If the resulting value is `null`, uses [defaultTo] if defined.
String readString(String field, {String defaultTo()});
}
Add formatOutput optional parameter to the GeneratorBuilder constructor. This is a lambda of the form String formatOutput(String originalCode) which a
formatOutput optional parameter to the GeneratorBuilder constructor.
This is a lambda of the form String formatOutput(String originalCode) which
allows you do do custom formatting.Support for package:analyzer 0.30.0
Support for package:build 0.9.0
Less verbose errors when analyzer fails to resolve the input.
Give more information when dartfmt fails.
dartfmt fails.Use the new log field instead of the deprecated buildStep.logger
log field instead of the deprecated buildStep.loggerSupport the latest release of pkg/dart_style.
pkg/dart_style.Update to latest build, build_runner, and build_test releases.
build, build_runner, and build_test releases.Don't throw when running against a non-library asset and getting no LibraryElement
BugFix: Always release the Resolver instance, even when generation does not run
Avoid some deprecated analyzer apis
Use library URIs (not names) to look up annotations in the mirror system.
Support the latest version of build package.
build package.Avoid calling computeNode() while instantiating annotation values
computeNode() while instantiating annotation valuesUpgrade to be compatible with the breaking changes in analyzer 0.28.0
Support package:analyzer 0.29.0
package:analyzer 0.29.0Remove "experimental" comment in README.md.
README.md.Support the latest version of pkg/build.
pkg/build.Generate valid strong-mode code for typed lists.
Added GeneratorBuilder option isStandalone to generate files that aren't part of source file.
Support the latest version of pkg/build.
pkg/build.Remove an outdated work-around.
Remove an outdated work-around.
Make strong-mode clean.
* Fixed multi-line error output.
Breaking: Switch to the build package for running Generators. This means that the top level build and generate functions are no longer available, and
Breaking: Switch to the build package for running Generators. This
means that the top level build and generate functions are no longer
available, and have been replaced by the top level build, watch, and
serve functions from the build package, and the GeneratorBuilder class.
See tool/build.dart, tool/watch.dart, and tool/phases.dart for usage.
build package is experimental, and likely to change.Breaking: The build package provides an abstraction for reading/writing
files via the BuildStep class, and that is now also provided to
Generator#generate and GeneratorForAnnotation#generateForAnnotatedElement
as a second argument.
Timestamps are no longer included in generated code.
There is no longer a need to specify the files related to an individual
generator via AssociatedFileSet. Simply use the BuildStep instance to read
and write files and the build package will track any files you read in and
run incremental rebuilds as necessary.
Added support for Symbol and Type in annotations.
Added support for Symbol and Type in annotations.
Improved error output when unable to create an instance from an annotation.
Nothing published for this version
* Upgrade to analyzer '^0.27.0'.
analyzer '^0.27.0'.Upgrade to analyzer '^0.27.1' and removed a work-around for a fixed analyzer issue.
analyzer '^0.27.1' and removed a work-around for a fixed
analyzer issue.JsonSerializableGenerator now supports classes with read-only properties.
JsonSerializableGenerator now supports classes with read-only properties.JsonSerializable: Added JsonKey annotation.
JsonSerializable: Added JsonKey annotation.
Improved output of generation errors and stack traces.
Require analyzer '^0.26.2'.
Your coding agent can read these notes before it upgrades. Set up the MCP server →