json_serializable.dart icon indicating copy to clipboard operation
json_serializable.dart copied to clipboard

Build Failure with Dart Test's Tags Annotation

Open PvtPuddles opened this issue 10 months ago • 0 comments

When using the Tags annotation for dart test, build runner fails with the following exception:

[SEVERE] json_serializable on test/integration_test.dart:

Could not resolve annotation for `library asset:my_project/test/integration_test.dart`.

I was able to reproduce the issue by:

  • Creating test/integration_test.dart (below)
  • Running builder runner
    • It didn't fail the first time, so I modified the file and ran it again, which then triggered the above build failure.

test/integration_test.dart:

@Tags(['integration-test']) // <-- Causes build_runner failure
library;

import 'package:test/test.dart';

void main() {
  test("example test", () {});
}

As a workaround, you can add the following to your build.yaml:

targets:
  $default:
    sources:
      exclude:
        - test/integration_test.dart

Of course, this only works if your tests don't rely on build_runner, so a more permanent solution would be most welcome.

PvtPuddles avatar Feb 24 '25 15:02 PvtPuddles