Open ghost opened 2 years ago
By adding the following seems to work for me
# objectbox_generator:generator:
# generate_for:
# - lib/core/auth/model/current_user.dart
# - lib/core/permission/model/permission.dart
source_gen:combining_builder:
generate_for:
- lib/**/model/*_input_data.dart
OK, so the issue is that the retrofit_generator
(which uses source_gen
) also outputs files named like *.g.dart
.
Your workaround works by restricting the input of source_gen
to your retrofit classes.
What we could do: https://github.com/dart-lang/build/blob/master/docs/faq.md#why-do-builders-need-unique-outputs suggests it might be possible to use "a more unique output extension". So maybe instead of objectbox.g.dart
the generator could use something like generated.obx.dart
. However, this would be a breaking change as imports need to be updated.
Changing the name would break existing apps though (if not configurable).
IIRC there was an option to combine outputs of multiple builders.
Could I ask why do you comment the option for objectbox_generator:generator
like this?
# objectbox_generator:generator:
# generate_for:
# - lib/core/auth/model/current_user.dart
# - lib/core/permission/model/permission.dart
@shic I believe this was the previous (and not successful) attempt of the original poster to resolve the conflict with the retrofit source generator. This isn't actually required when using ObjectBox with Flutter or Dart, if that is your question.
To resolve the conflict with the retrofit source generator, the other configuration for that tool was added (because it appears to use source_gen
).
@greenrobot-team
To resolve the conflict with the retrofit source generator, the other configuration for that tool was added (because it appears to use
source_gen
).
Thanks for your reply, I used json_serializable package to generate data model for my project. Now I added objectbox and when I tried to generate models for objectbox, got the following error:
[SEVERE] Conflicting outputs
Both objectbox_generator:generator and source_gen:combining_builder may output lib/objectbox.g.dart. Potential outputs must be unique across all builders. See https://github.com/dart-lang/build/blob/master/docs/faq.md#why-do-builders-need-unique-outputs
pub finished with exit code 78
You said "the other configuration for that tool was added", but I am not using retrofit, I am using json_serializable (it use source_gen).
I did not understand how to solve this problem in my case. Could you help me? Thanks
@shic Is the file containing your data model classes named objectbox.dart
? In that case I suggest to just rename it.
The issue is that json_serializable
produces <filename>.g.dart
for each file containing annotated entities. objectbox_generator:generator
always generates objectbox.g.dart
, regardless in which file the model classes are. So if the file with JSON annotated classes is called objectbox.dart
the two generators will both try to generate objectbox.g.dart
.
objectbox.g.dart
!I have a lot of generators that were causing objectbox.g.dart generation issues:
dev_dependencies:
build_runner: ^2.2.0
shelf_router_generator: ^1.0.3
json_serializable: ^6.3.1
freezed: ^2.1.0+1
objectbox_generator: ^1.6.0
# build.yaml
targets:
$default:
builders:
source_gen:combining_builder:
generate_for:
- "**/[!objectbox]**.dart"
source_gen:combining_builder - resolves builders results from to single file *.g.dart objectbox_generator:generator break work source_gen:combining_builder for files objectbox.dart / objectbox.g.dart
glob pattern **/[!objectbox]**.dart
excludes any objectbox files, but safe all another for source_gen:combining_builder
P.S. i set output_dir to lib/objectbox/
# pubspec.yaml
objectbox:
output_dir: objectbox
hello, can you explain me how to fix problem, im beginer in flutter. I have in pubspec jsonserializable and retrofit, and have problem with generation code in object box. For most project i use isar but i d'like try onjectbox
@PrzemyslawPluszowy There are two solutions described in the last two comments (renaming the source file or adding a configuration in build.yaml). Why do these not work for you?
:rotating_light: First, please check:
current_user.dart
insidelib
folder:flutter pub run build_runner build --delete-conflicting-outputs
Basic info (please complete the following information):
Additionally, you can choose to provide more details, e.g. the output of:
pub deps --no-dev
flutter doctor -v
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/jiewang/Library/Android/sdk • Platform android-30, build-tools 31.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) • All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 13.1, Build version 13A1030d • CocoaPods version 1.11.2
[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2020.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] VS Code (version 1.62.3) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.29.0
[✓] Connected device (1 available) • Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.55
• No issues found!
name: admin description: Admin
publish_to: 'none'
version: 1.0.0+1
environment: sdk: '>=2.12.0 <3.0.0'
dependencies: animations: ^2.0.2 auto_route: ^3.1.3 cupertino_icons: ^1.0.2 dartz: ^0.10.0 dio: ^4.0.3 enum_to_string: ^2.0.1 flare_flutter: ^3.0.2 flex_color_scheme: ^4.0.0 flutter: sdk: flutter flutter_breadcrumb: ^1.0.1 flutter_hooks: ^0.18.1 flutter_secure_storage: ^5.0.2 freezed_annotation: ^1.0.0 graphql: ^5.0.0 hooks_riverpod: ^1.0.0 json_annotation: ^4.3.0 logger: ^1.1.0 objectbox: ^1.3.0 objectbox_flutter_libs: ^1.3.0 path: ^1.8.0 path_provider: ^2.0.7 retrofit: ^3.0.0 snapping_sheet: ^3.1.0 sqlite3_flutter_libs: ^0.5.1 ua_client_hints: ^1.1.0
dev_dependencies: auto_route_generator: ^3.1.0 build_runner: ^2.1.5 flutter_lints: ^1.0.0 flutter_test: sdk: flutter freezed: ^1.0.0 json_serializable: ^6.0.1 objectbox_generator: ^1.3.0 retrofit_generator: ^3.0.0+1
flutter:
The following line ensures that the Material Icons font is
import 'package:objectbox/objectbox.dart';
@Entity() class CurrentUser { @Id(assignable: true) int? localId; @Unique() String? id; @Property(type: PropertyType.date) DateTime createdAt; @Property(type: PropertyType.date) DateTime? updatedAt;
CurrentUser({ this.localId, this.id, required this.createdAt, this.updatedAt, }); }
part 'login_remote_data_source.g.dart';
final loginRemoteDataSourceProvider = Provider((ref) {
return LoginRemoteDataSource(ref.read);
});
@RestApi() abstract class LoginRemoteDataSource { factory LoginRemoteDataSource(Reader reader) => _LoginRemoteDataSource(reader(dioProvider));
@POST('auth/login') Future login(@Body() LoginInputData loginInputData);
}
[WARNING] Bootstrap: Invalidated precompiled build script due to missing asset graph. [INFO] Bootstrap:Precompiling build script...... [INFO] Bootstrap:Precompiling build script... completed, took 1.1s
[INFO] BuildDefinition:Initializing inputs [INFO] BuildDefinition:Building new asset graph... [SEVERE] BuildDefinition: Conflicting outputs Both objectbox_generator:generator and source_gen:combining_builder may output lib/objectbox.g.dart. Potential outputs must be unique across all builders. See https://github.com/dart-lang/build/blob/master/docs/faq.md#why-do-builders-need-unique-outputs package:build_runner_core/src/asset_graph/graph.dart 507:11 AssetGraph._addGeneratedOutputs package:build_runner_core/src/asset_graph/graph.dart 452:21 AssetGraph._addInBuildPhaseOutputs package:build_runner_core/src/asset_graph/graph.dart 411:26 AssetGraph._addOutputsForSources package:build_runner_core/src/asset_graph/graph.dart 71:9 AssetGraph.build package:build_runner_core/src/generate/build_definition.dart 253:41 _Loader.prepareWorkspace.
package:build_runner_core/src/generate/build_definition.dart 251:64 _Loader.prepareWorkspace.
package:build_runner_core/src/logging/logging.dart 25:30 logTimedAsync
package:build_runner_core/src/generate/build_definition.dart 251:13 _Loader.prepareWorkspace
package:build_runner_core/src/generate/build_impl.dart 114:27 BuildImpl.create
package:build_runner_core/src/generate/build_runner.dart 34:26 BuildRunner.create
package:build_runner/src/generate/build.dart 109:17 build
package:build_runner/src/entrypoint/build.dart 35:18 BuildCommand._run
package:args/command_runner.dart 209:13 CommandRunner.runCommand
package:build_runner/src/entrypoint/run.dart 26:18 run
.dart_tool/build/entrypoint/build.dart 39:16 main
[+6787 ms] "flutter run" took 6,969ms. [ +7 ms] pub finished with exit code 78 [ +1 ms]
0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
[ +95 ms] ensureAnalyticsSent: 93ms [ +1 ms] Running shutdown hooks [ ] Shutdown hooks complete [ ] exiting with code 78