genesis_generator

genesis version genesis_generator version Pub likes Test on multiple Dart SDKs Runtime coverage

Generates typed startup registrations and diagnostic graphs for Genesis. Use Dart 3.9 or later to run the generator.

Installation

Add the Genesis runtime to your application and add the generator and build_runner as development dependencies.

dependencies:
  genesis: ^2.0.1

dev_dependencies:
  build_runner: ^2.7.1
  genesis_generator: ^2.0.1

Run dart pub get in your app directory. For a Flutter app, run flutter pub get instead.

Usage

Define and generate startup tasks

In lib/genesis.dart, declare typed providers and annotated startup tasks. The generator uses each task parameter's type to find the value it needs.

import 'package:genesis/genesis.dart';

part 'genesis.g.dart';

/// The message printed by the startup task.
class Greeting {
  const Greeting(this.message);

  final String message;
}

@GenesisProvider()
Greeting _greeting() => const Greeting('Hello from Genesis!');

@GenesisTask(phase: GenesisTaskPhase.execution)
void _start(Greeting greeting) {
  print(greeting.message);
}

Generate from the application package directory.

dart run build_runner build

Use dart run build_runner watch to regenerate as you edit. The builder writes lib/genesis.g.dart and .dart_tool/genesis_graph.json.

Run and validate startup

In bin/main.dart, import the application's startup library and await runGenesis(). Replace genesis_example with your application's package name.

import 'package:genesis_example/genesis.dart';

Future<void> main() async {
  await runGenesis();
}

Run the application and validate its startup graph from the same package.

dart run bin/main.dart
dart run genesis:doctor --check

See the runnable example for the workspace setup, annotated tasks, and application entry point.

Generated registrations

  • Typed provider registrars for @GenesisProvider functions.
  • Task descriptors for configure, init, and execution.
  • A GenesisPackageManifest used by runtime diagnostics.
  • Bootstrap functions for directly imported Genesis dependencies.

@GenesisProvider and @GenesisTask(phase: ...) methods may use required positional provider object parameters. The generator injects those values with genesisReadProvider<T>() and records the inferred parameter metadata. @GenesisTask(requires: ...) records order-only dependencies, and @GenesisTask(provides: ...) records readiness tokens that do not require a function return value.

@GenesisProvider(eager: true) is emitted into both provider descriptors and graph metadata. Task GenesisCondition values are emitted into task descriptors and the graph so runtime planning and doctor output stay aligned.

The builder checks that lib/genesis.dart imports each direct Genesis dependency. It checks for duplicate type sources, provider cycles, and invalid phase dependencies after applying task conditions for each platform and build mode. Mutually exclusive task outputs can share a type. Run Doctor on the resulting graph to check for missing dependencies.

Documentation

Libraries

genesis_generator