talira

build_version

Put your Dart package's version into your source code

open sourceBSD-3-Clausefree

build_version writes the version from a Dart package's pubspec.yaml into a generated source file (lib/src/version.dart by default), so code can read its own version. It runs either as a standalone CLI with dart run build_version@, which needs no build_runner and can --check the file in CI, or as a build_runner builder for packages that already run other builders, checked in tests with build_verify.

Problems it solves

  • show my Dart package's version from inside its code
  • keep a version constant in sync with pubspec.yaml
  • fail CI when the generated version file is out of date

Features

  • generates a Dart file holding the package's pubspec version
  • standalone CLI with no dev_dependencies needed
  • --check mode to verify the generated file in CI
  • a build_runner builder with a configurable output path

Limitations

  • The standalone CLI needs Dart 3.12 or newer.1

Alternatives

The same job

These do what build_version does.

  1. source_gen A framework for writing Dart code generators

Compare build_version with the top 3