objectbox-dart
objectbox-dart copied to clipboard
Generator output conflicts with retrofit builder
:rotating_light: First, please check:
- existing issues,
- FAQs https://github.com/objectbox/objectbox-dart#faq
- create a model
current_user.dartinsidelibfolder:
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,
});
}
- run
flutter pub run build_runner build --delete-conflicting-outputs - get error:
[INFO] Initializing inputs
[INFO] Building new asset graph...
[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
[INFO] Terminating. No further builds will be scheduled
Basic info (please complete the following information):
- ObjectBox version: [1.3.0]
- Flutter/Dart SDK: [2.5.3 / 2.14.4]
- Null-safety enabled: [yes]
- Reproducibility: [always]
- OS: [ macOs BigSur]
- Device/Emulator: [iPhone 13]
Additionally, you can choose to provide more details, e.g. the output of:
pub deps --no-dev
Dart SDK 2.14.4
Flutter SDK 2.5.3
admin 1.0.0+1
|-- animations 2.0.2
| '-- flutter...
|-- auto_route 3.1.3
| |-- collection 1.15.0
| |-- flutter...
| |-- path...
| '-- universal_html 2.0.8
| |-- async 2.8.1
| | |-- collection...
| | '-- meta...
| |-- charcode 1.3.1
| |-- collection...
| |-- csslib 0.17.1
| | '-- source_span...
| |-- html 0.15.0
| | |-- csslib...
| | '-- source_span...
| |-- meta...
| |-- source_span 1.8.1
| | |-- collection...
| | |-- path...
| | '-- term_glyph 1.2.0
| |-- typed_data...
| '-- universal_io 2.0.4
| |-- collection...
| |-- crypto...
| |-- meta...
| '-- typed_data...
|-- cupertino_icons 1.0.4
|-- dartz 0.10.0
|-- dio 4.0.3
| |-- http_parser 4.0.0
| | |-- charcode...
| | |-- collection...
| | |-- source_span...
| | |-- string_scanner 1.1.0
| | | |-- charcode...
| | | '-- source_span...
| | '-- typed_data...
| '-- path...
|-- enum_to_string 2.0.1
|-- flare_flutter 3.0.2
| |-- collection...
| |-- flutter...
| '-- meta 1.7.0
|-- flex_color_scheme 4.0.0
| '-- flutter...
|-- flutter 0.0.0
| |-- characters 1.1.0
| |-- collection...
| |-- meta...
| |-- sky_engine 0.0.99
| |-- typed_data 1.3.0
| | '-- collection...
| '-- vector_math 2.1.0
|-- flutter_breadcrumb 1.0.1
| |-- flutter...
| '-- pedantic 1.11.1
|-- flutter_hooks 0.18.1
| '-- flutter...
|-- flutter_secure_storage 5.0.2
| |-- flutter...
| |-- flutter_secure_storage_linux 1.1.0
| | |-- flutter...
| | '-- flutter_secure_storage_platform_interface...
| |-- flutter_secure_storage_macos 1.1.0
| | |-- flutter...
| | '-- flutter_secure_storage_platform_interface...
| |-- flutter_secure_storage_platform_interface 1.0.0
| | |-- flutter...
| | '-- plugin_platform_interface 2.0.2
| | '-- meta...
| |-- flutter_secure_storage_web 1.0.2
| | |-- flutter...
| | |-- flutter_secure_storage_platform_interface...
| | |-- flutter_web_plugins 0.0.0
| | | |-- characters...
| | | |-- collection...
| | | |-- flutter...
| | | |-- js...
| | | |-- meta...
| | | |-- typed_data...
| | | '-- vector_math...
| | '-- js 0.6.3
| |-- flutter_secure_storage_windows 1.1.2
| | |-- flutter...
| | '-- flutter_secure_storage_platform_interface...
| '-- meta...
|-- freezed_annotation 1.0.0
| |-- collection...
| |-- json_annotation...
| '-- meta...
|-- graphql 5.0.0
| |-- collection...
| |-- gql 0.13.1-alpha+1635885531641
| | |-- collection...
| | |-- meta...
| | '-- source_span...
| |-- gql_dedupe_link 2.0.0
| | |-- async...
| | |-- gql_exec...
| | |-- gql_link...
| | '-- meta...
| |-- gql_error_link 0.2.0
| | |-- async...
| | |-- gql_exec...
| | |-- gql_link...
| | '-- meta...
| |-- gql_exec 0.3.0
| | |-- collection...
| | |-- gql...
| | '-- meta...
| |-- gql_http_link 0.4.0
| | |-- gql...
| | |-- gql_exec...
| | |-- gql_link...
| | |-- http...
| | |-- http_parser...
| | '-- meta...
| |-- gql_link 0.4.0
| | |-- gql...
| | |-- gql_exec...
| | '-- meta...
| |-- gql_transform_link 0.2.0
| | |-- gql_exec...
| | '-- gql_link...
| |-- hive 2.0.4
| | |-- crypto 3.0.1
| | | |-- collection...
| | | '-- typed_data...
| | '-- meta...
| |-- http 0.13.4
| | |-- async...
| | |-- http_parser...
| | |-- meta...
| | '-- path...
| |-- meta...
| |-- normalize 0.5.5
| | |-- collection...
| | '-- gql...
| |-- path...
| |-- rxdart 0.26.0
| |-- stream_channel 2.1.0
| | '-- async...
| |-- uuid 3.0.5
| | '-- crypto...
| '-- web_socket_channel 2.1.0
| |-- async...
| |-- crypto...
| '-- stream_channel...
|-- hooks_riverpod 1.0.0
| |-- collection...
| |-- flutter...
| |-- flutter_hooks...
| |-- flutter_riverpod 1.0.0
| | |-- collection...
| | |-- flutter...
| | |-- meta...
| | |-- riverpod...
| | '-- state_notifier...
| |-- riverpod 1.0.0
| | |-- collection...
| | |-- meta...
| | '-- state_notifier...
| '-- state_notifier 0.7.1
| '-- meta...
|-- json_annotation 4.3.0
| '-- meta...
|-- logger 1.1.0
|-- objectbox 1.3.0
| |-- collection...
| |-- ffi 1.1.2
| |-- meta...
| '-- path...
|-- objectbox_flutter_libs 1.3.0
| |-- objectbox...
| '-- path_provider...
|-- path 1.8.0
|-- path_provider 2.0.7
| |-- flutter...
| |-- path_provider_android 2.0.7
| | |-- flutter...
| | '-- path_provider_platform_interface...
| |-- path_provider_ios 2.0.7
| | |-- flutter...
| | '-- path_provider_platform_interface...
| |-- path_provider_linux 2.1.2
| | |-- flutter...
| | |-- path...
| | |-- path_provider_platform_interface...
| | '-- xdg_directories 0.2.0
| | |-- meta...
| | |-- path...
| | '-- process 4.2.4
| | |-- file 6.1.2
| | | |-- meta...
| | | '-- path...
| | |-- path...
| | '-- platform...
| |-- path_provider_macos 2.0.3
| | '-- flutter...
| |-- path_provider_platform_interface 2.0.1
| | |-- flutter...
| | |-- meta...
| | |-- platform 3.0.2
| | '-- plugin_platform_interface...
| '-- path_provider_windows 2.0.4
| |-- ffi...
| |-- flutter...
| |-- meta...
| |-- path...
| |-- path_provider_platform_interface...
| '-- win32 2.3.0
| '-- ffi...
|-- retrofit 3.0.0
| |-- dio...
| '-- meta...
|-- snapping_sheet 3.1.0
| '-- flutter...
|-- sqlite3_flutter_libs 0.5.1
| '-- flutter...
'-- ua_client_hints 1.1.0
'-- flutter...
flutter doctor -v
Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-x64, locale en-DE)
• Flutter version 2.5.3 at /usr/local/Caskroom/flutter/2.2.2/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 18116933e7 (7 weeks ago), 2021-10-15 10:46:35 -0700
• Engine revision d3ea636dc5
• Dart version 2.14.4
[✓] 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!
Steps to reproduce
- create a model
model.dart; - run
flutter pub run build_runner build --delete-conflicting-outputs - See error
Expected behavior
Should have no errors and generate objectbox.g.dart and objectbox-model.json files.
Code
See above
- Include your pubspec.yaml.
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
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/Teddy.flr
#- assets/fonts
#- assets/images
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
- Include affected entity classes.
current_user.dart:
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,
});
}
login_remote_data_source.dart, generated by retrofit, all other classes are generated by freezed without @Entity() annotation.
part 'login_remote_data_source.g.dart';
final loginRemoteDataSourceProvider = Provider<LoginRemoteDataSource>((ref) {
return LoginRemoteDataSource(ref.read);
});
@RestApi()
abstract class LoginRemoteDataSource {
factory LoginRemoteDataSource(Reader reader) =>
_LoginRemoteDataSource(reader(dioProvider));
@POST('auth/login')
Future<CurrentUser> login(@Body() LoginInputData loginInputData);
}
- Please remove any unnecessary or confidential parts.
- At best, link to or attach a project with a failing test.
Logs, stack traces
[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.<fn>
package:build_runner_core/src/generate/build_definition.dart 251:64 _Loader.prepareWorkspace.<fn>
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)
#1 _DefaultPub.interactively (package:flutter_tools/src/dart/pub.dart:391:7)
<asynchronous suspension>
#2 PackagesForwardCommand.runCommand (package:flutter_tools/src/commands/packages.dart:247:5)
<asynchronous suspension>
#3 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1125:27)
<asynchronous suspension>
#4 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#5 CommandRunner.runCommand (package:args/command_runner.dart:209:13)
<asynchronous suspension>
#6 FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:288:9)
<asynchronous suspension>
#7 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#8 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:236:5)
<asynchronous suspension>
#9 run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
<asynchronous suspension>
#10 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#11 main (package:flutter_tools/executable.dart:92:3)
<asynchronous suspension>
[ +95 ms] ensureAnalyticsSent: 93ms
[ +1 ms] Running shutdown hooks
[ ] Shutdown hooks complete
[ ] exiting with code 78
Additional context
Add any other context about the problem here.
- Is there anything special about your app?
- May transactions or multi-threading play a role?
- Did you find any workarounds to prevent the issue?
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.
Finded solution for fix most problems with generate 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
Resolution:
# 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?