Skip to content

Support newer analyzer and source gen versions #719

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ env:
DART_VERSION: 3.7.2 # Available versions: https://dart.dev/get-dart/archive

jobs:
analyze-and-format:
format-and-analyze:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
Expand All @@ -33,6 +33,13 @@ jobs:
dart pub get --directory=generator
dart pub get --directory=objectbox
dart pub get --directory=objectbox_test
flutter pub get --directory=flutter_libs
flutter pub get --directory=sync_flutter_libs
# Since Dart 3.7, dart format needs pub get to run before formatting,
# so to check formatting of Flutter packages run pub get for them as well.
# Also run before generating code to exclude generated code.
- name: Check formatting of all packages
run: dart format --set-exit-if-changed .
- name: Generate code (benchmark)
working-directory: benchmark
run: dart run build_runner build
Expand All @@ -45,13 +52,6 @@ jobs:
dart analyze generator
dart analyze objectbox
dart analyze objectbox_test
- name: Check formatting of all packages
# Since Dart 3.7, dart format needs pub get to run before formatting,
# so to check formatting of Flutter packages run pub get for them first.
run: |
flutter pub get --directory=flutter_libs
flutter pub get --directory=sync_flutter_libs
dart format --set-exit-if-changed .

pana:
runs-on: ubuntu-24.04
Expand Down
18 changes: 9 additions & 9 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ variables:
key: "linux-x64-dart-$DART_VERSION-pub-cache"

# Analyze (only) Dart packages, check formatting in Dart and Flutter packages.
analyze-and-format:
format-and-analyze:
extends: .cache
stage: code-analysis
script:
Expand All @@ -43,6 +43,14 @@ analyze-and-format:
- dart pub get --directory=objectbox
- dart pub get --directory=objectbox_test
- dart pub get --directory=objectbox/example/dart-native/vectorsearch_cities
# Since Dart 3.7, dart format needs pub get to run before formatting,
# so can no longer check formatting of Flutter packages (would require Flutter SDK):
# Check formatting only for Dart packages (run before generating code to exclude generated code)
- dart format --set-exit-if-changed benchmark
- dart format --set-exit-if-changed generator
- dart format --set-exit-if-changed objectbox
- dart format --set-exit-if-changed objectbox_test
- dart format --set-exit-if-changed objectbox/example/dart-native
# Generate code
- cd benchmark
- dart run build_runner build
Expand All @@ -57,14 +65,6 @@ analyze-and-format:
- dart analyze objectbox
- dart analyze objectbox_test
- dart analyze objectbox/example/dart-native/vectorsearch_cities
# Since Dart 3.7, dart format needs pub get to run before formatting,
# so can no longer check formatting of Flutter packages (would require Flutter SDK):
# Check formatting only for Dart packages
- dart format --set-exit-if-changed benchmark
- dart format --set-exit-if-changed generator
- dart format --set-exit-if-changed objectbox
- dart format --set-exit-if-changed objectbox_test
- dart format --set-exit-if-changed objectbox/example/dart-native

# Runs generator integration tests, e.g. ensures generator works as expected.
# Note: no need to test oldest SDK here, generator package is also built as part of unit-tests job.
Expand Down
3 changes: 2 additions & 1 deletion generator/lib/src/code_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ class CodeBuilder extends Builder {
var code = CodeChunks.objectboxDart(model, imports, pubspec);

try {
code = DartFormatter().format(code);
code = DartFormatter(languageVersion: DartFormatter.latestLanguageVersion)
.format(code);
} finally {
// Write the code even after a formatter error so it's easier to debug.
final codeId = AssetId(
Expand Down
4 changes: 0 additions & 4 deletions generator/lib/src/entity_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,6 @@ class EntityResolver extends Builder {
case IndexType.hash64:
prop.flags |= OBXPropertyFlags.INDEX_HASH64;
break;
default:
throw InvalidGenerationSourceError(
"Entity '${elementBare.name}': index type $indexType not supported.",
element: f);
}
}

Expand Down
35 changes: 17 additions & 18 deletions generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@ homepage: https://objectbox.io
version: 4.1.0

environment:
sdk: '>=2.18.0 <4.0.0'
sdk: '^3.5.0' # analyzer 6.5.0 requires meta 1.14.0 requires Flutter SDK 3.24.0 requires 3.5.0

dependencies:
objectbox: 4.1.0
analyzer: '>=5.2.0 <7.0.0' # 5.1.0 has a bug where DartType.element has been removed.
build: ^2.0.0
collection: ^1.15.0
dart_style: ^2.0.0
glob: ^2.0.0
path: ^1.8.0
source_gen: ^1.0.0
pubspec_parse: ^1.0.0
yaml: ^3.0.0
http: '>=0.13.5 <2.0.0'
pointycastle: ^3.7.3 # 3.7.4 requires Dart 3, but still supporting 2.18
analyzer: '>=6.5.0 <8.0.0' # dart_style 2.3.7 requires 6.5.0
build: ^2.4.1
collection: ^1.18.0 # Would require 1.19.1, but Flutter 3.24.0 has 1.18.0 pinned
dart_style: '>=2.3.7 <4.0.0' # require 2.3.7 for languageVersion in DartFormatter constructor
glob: ^2.1.3
path: ^1.9.1
source_gen: ">=1.5.0 <3.0.0"
pubspec_parse: ^1.4.0
yaml: ^3.1.3
http: ^1.3.0
pointycastle: ^4.0.0

dev_dependencies:
test: ^1.16.5
# lints 2.1.0+ requires Dart 3, but CI still tests with Dart 2, but also need 3.0.0+ to match pana
lints: '>=2.0.1 <4.0.0'
pub_semver: ^2.1.3
package_config: ^2.1.0
build_test:
test: ^1.25.8
lints: ^3.0.0
pub_semver: ^2.2.0
package_config: ^2.2.0
build_test: ^2.2.2
2 changes: 2 additions & 0 deletions objectbox/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## latest

* Allow analyzer 7, dart_style 3, source_gen 2 and pointycastle 4.
* Examples: demos are compatible with JDK 21 included with Android Studio Ladybug or later, require
Flutter SDK 3.24 (with Dart SDK 3.5) or newer.
* Requires at least Dart SDK 3.4 or Flutter SDK 3.22.

## 4.1.0 (2025-02-04)

Expand Down
Loading