Skip to content
pubscout

build_version

2.2.1, released 5 weeks ago by kevmoo.com

Generate a Dart file with the package version at build time.

$ flutter pub add build_version
Source repository

What it does

`build_version` extracts the `version` field from a pubspec and writes it to a Dart file. It can run as a standalone CLI or as a build_runner builder, supporting custom output paths and CI verification.

AI-written summary of version 2.2.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need a compile‑time constant for the package version
  • You already use build_runner for other generators
  • You want CI to verify the generated file matches pubspec

Skip it when

  • You only need the version at runtime and can read pubspec directly
  • You prefer a pure Dart solution without code generation

Strengths

  • Zero runtime overhead
  • Supports both CLI and build_runner workflows
  • Customizable output path
  • CI friendly `--check` flag

Weaknesses

  • Requires Dart 3.12+
  • Adds a build step to the project
  • Only handles the version field, not other metadata

Setup

Kind
Pure Dart
Effort
Low
Code generation
Yes (build_runner)
Direct dependencies
4

Add `build_version` to dev_dependencies and run `dart run build_runner build` or use the CLI directly. No special permissions needed.

```dart
// lib/src/version.dart (generated)
const packageVersion = '1.2.3';
```

Alternatives

Packages that do the same job and could replace build_version.

Works with

Packages commonly used together with build_version: ones it builds on, ones built on it, and its own family.