Succeeded after 6.7s with 0 outputs (2 actions)
Run build_runner clean first. Then paste the output of build_runner build --verbose
first i carried out flutter packages pub run build_runner clean , then carried out flutter packages pub run build_runner build --verbose, but the command line returned to me is Build:Succeeded after 11.1s with 0 outputs (2 actions)
Do you have any files annotated w/ @JsonSerializable?
@kevmoo There is a @JsonSerializable annotation, or 2 actions will not be captured. The example I use is the user.dart example of flutter's official website.
You're following along here? https://flutter.dev/docs/development/data-and-backend/json#creating-model-classes-the-json_serializable-way
Do you have these items in your pubspec?
dependencies:
# Your other regular dependencies here
json_annotation: ^2.0.0
dev_dependencies:
# Your other dev_dependencies here
build_runner: ^1.0.0
json_serializable: ^2.0.0
@kevmoo yes
Hrm......
run a clean again, then run build --verbose and paste the output?
There was same problem in my project and I found solution.
Problem was, class name and file name did not same.
When I rename file as class name, the problem was solved.
That's interesting @hasimyerlikaya – as far as I know, the name of the file should have no affect.
For model.dart must be part "model.g.dart";
Not class name, sorry @kevmoo
@kevmoo this is my output:
[INFO] Generating build script...
[INFO] Generating build script completed, took 367ms
[INFO] Creating build script snapshot......
[INFO] Creating build script snapshot... completed, took 11.8s
[INFO] BuildDefinition:Initializing inputs
[INFO] BuildDefinition:Building new asset graph...
[INFO] BuildDefinition:Building new asset graph completed, took 676ms
[INFO] BuildDefinition:Checking for unexpected pre-existing outputs....
[INFO] BuildDefinition:Checking for unexpected pre-existing outputs. completed, took 1ms
[INFO] Build:Running build...
[INFO] Heartbeat:1.0s elapsed, 0/1 actions completed.
[FINE] json_serializable on test/widget_test.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable on test/widget_test.dart:Running JsonLiteralGenerator - 2 of 2
[INFO] Build:Running build completed, took 6.8s
[INFO] Build:Caching finalized dependency graph...
[INFO] Build:Caching finalized dependency graph completed, took 41ms
[INFO] Build:Succeeded after 6.8s with 0 outputs (2 actions)
@kevmoo My source construction file code is as follows:
import 'package:json_annotation/json_annotation.dart';
part 'user.g.dart';
@JsonSerializable()
class User {
User(this.name, this.email);
String name;
String email;
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
Map<String, dynamic> toJson() => _$UserToJson(this);
}
I don't know which step is misconfigured, because it's entirely in accordance with the official website, can you help me look at it? @kevmoo and @hasimyerlikaya
my filename is user.dart
What's in your build.yaml file?
For some reason, the builder is not running against any code in your lib directory.
Also: WHERE is user.dart?
The location of the user.dart file is in / -> app -> model -> user.dart
There is no build.yaml file in my project. Is this file not necessary?
The location of the user.dart file must be specified, I remember it seems to be in any folder of the project.
@kevmoo
It turns out that this library can only convert files in the lib directory, because I used to write web projects, so I think the lib directory is the tool library. I will use the app directory as my project directory. Is there any way to change it? Is the effective directory?
I don't think we support files in app – unless you explicitly put it in the sources in build.yaml
targets:
$default:
builders:
json_serializable:
generate_for:
include:
- app/model/*
- lib/*
This is my build.yaml file, lib/* is in effect, but app/model/* does not take effect.
Well, I tested that I found that the model files in the lib and example directories in build.yaml can detect and generate the corresponding g.dart, but my custom app directory is not working. I think since the example directory line, Should also support customizing other directory names.
å¤§ä½¬ä»¬ã€‚è¿™ä¸ªé—®é¢˜æ€Žä¹ˆè§£å†³çš„å‘€ã€‚æˆ‘çŽ°åœ¨ä¹Ÿæ˜¯è¿™ä¸ªé—®é¢˜æ— æ³•è§£å†³
@jakemac53 @natebosch – do we only support some top-level directories?
By default we only include the directories specified in the pub package layout conventions.
You can customize the files that are included for your app though, using the sources config for a target:
targets:
$default:
# Override the default source globs, we don't include `app/` by default
sources:
- pubspec.*
- lib/**
- app/**
@jakemac53 @kevmoo Good! It turned out that my previous build. yaml configuration was a bit of a problem, as you said, the configuration has achieved the desired effect, thank you.
@jakemac53 – wondering if there is something we could do to make this easier?
Maybe print a warning if generate_for includes files not in sources?
Maybe print a warning if
generate_forincludes files not insources?
That get's a little tricky since they are both globs and the overlap of globs isn't always easy to reason about.
It's plausible that we could detect when there is a genarate_for glob that matches zero sources, but we'll need to be cautious not to take the defaults provided with the builder into account for that...
Tracking at https://github.com/dart-lang/build/issues/2111
My issue was funny...I put the models folder outside lib folder for flutter
My issue was funny...I put the models folder outside lib folder for flutter
Rarely (if ever) should you have model code outside of lib
Most helpful comment
For model.dart must be part "model.g.dart";
Not class name, sorry @kevmoo