Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to create a builder that requires files generated by other builder_runners? #2982

Closed
lcdsmao opened this issue Jan 30, 2021 · 1 comment

Comments

@lcdsmao
Copy link

lcdsmao commented Jan 30, 2021

Dart SDK Version (dart --version)

Dart SDK version: 2.10.5 (stable) (Tue Jan 19 13:05:37 2021 +0100) on "macos_x64"

What package(s) from this repo you are using, and the version (i.e. build_runner 0.7.12)

  • If you are not sure, try checking your pubspec.lock file.
dependencies:
  build: ^1.3.0
  json_annotation: ^3.1.1

dev_dependencies:
  build_runner: ^1.11.0
  json_serializable: ^3.5.1

What builder(s) you are using (or writing yourself). Try to give a short summary of what they do.

Sample repo: https://github.com/lcdsmao/custom-builder-with-build-runner

A builder that import file that needs part generated by json_serializable.

When executing dart pub run build_runner build, the following error occurs:

[SEVERE] Failed to snapshot build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.
[SEVERE] lib/src/example.dart:3:6: Error: Error when reading 'lib/src/example.g.dart': No such file or directorypart 'example.g.dart';     ^lib/src/example.dart:3:6: Error: Can't use 'lib/src/example.g.dart' as a part, because it has no 'part of' declaration.part 'example.g.dart';     ^lib/src/example.dart:11:57: Error: Method not found: '_$PersonFromJson'.  factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);                                                        ^^^^^^^^^^^^^^^^lib/src/example.dart:12:36: Error: The method '_$PersonToJson' isn't defined for the class 'Person'. - 'Person' is from 'package:builder_test/src/example.dart' ('lib/src/example.dart').Try correcting the name to the name of an existing method, or defining a method named '_$PersonToJson'.  Map<String, dynamic> toJson() => _$PersonToJson(this);                                   ^^^^^^^^^^^^^^

If I comment out the import import 'src/example.dart';, then example.g.dart can be generated successfully.

@jakemac53
Copy link
Contributor

There is no supported way of doing this today - you can move the generated files to another package which is the easiest way to deal with it.

Closing as we don't have any actionable plan to deal with this - we do face the same problem in our own repos as well fwiw but there just isn't a good solution we have come up with to manage it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants