Jonathan Jonathan -4 years ago 134
Dart Question

implement a build generator with serializable in dart

I want to use the package serializable to serialize some classes and one custom generator to spit out some extra info from the same classes. My problem is that build is complaining that I can't overwrite the inputs:

[INFO] Build: Reading cached dependency graph completed, took 12ms
[INFO] Build: Finalizing build setup completed, took 43ms
[SEVERE] Build: Failed after 2775ms
InvalidOutputException: mongaba_model|lib/models/calltoaction.g.dart
Cannot overwrite inputs.

How can I use serializable and also create a custom generator to use on the same classes?


Answer Source

Found the problem. I was using two phases:


main() async {
  PhaseGroup pg = new PhaseGroup()
    ..addPhase(serializablePhase(const ['lib/models/*.dart']))
    ..addPhase(modelablePhase(const ['lib/models/*.dart']));

  await build(pg,
      deleteFilesByDefault: true);

Now I changed to use two generators within the same phase:


modelablePhase([Iterable<String> globs = const ['bin/**.dart', 
'web/**.dart', 'lib/**.dart']]) =>
new Phase()..addAction(
    new GeneratorBuilder(const
      [const ModelableGenerator(), const SerializableGenerator()]
    new InputSet(new PackageGraph.forThisPackage(), globs));

added this answer that it maybe can help someone

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download