feat(phase-1/m1a): platform-neutral data layer + :core:data-jvm

Phase 1 milestone M1a (Development Plan §6, desktop track): make the whole
data layer usable from a non-Android build, without touching what the
Android app compiles.

:core:data splits its sources:
  src/main/kotlin      platform-neutral — entities, repository, field
                       crypto, NoteCryptoService. Compiled by BOTH
                       :core:data and :core:data-jvm. Must not import
                       android.*
  src/androidMain/kotlin  Android-only seam implementations.

Two seams were required, both identified by the Phase-0 spike:
  ObjectBoxStore          Context on Android, a directory on desktop. Same
                          FQN in sibling modules that are never on one
                          classpath — which is also what keeps
                          objectbox-android and objectbox-java (they ship
                          the same io.objectbox.* classes) apart.
  ImageOrientationNormalizer  EXIF rotation needs a bitmap decoder; the
                          implementation moved verbatim out of
                          NoteRepositoryImpl, which is now platform-free.
                          The parameter is required, not defaulted, so a
                          platform that forgets it fails the build.

New :core:data-jvm compiles those shared sources against objectbox-java /
objectbox-linux with its own codegen. `:core:data-jvm:smoke` runs the real
NoteRepositoryImpl (save + hashtags + attachment round-trip + close/reopen)
on the JVM: PASS, with the generator reporting "ID model file unchanged" —
one schema, two generated runtimes.

Also: .gitignore excluded **/objectbox-models/, so the schema contract was
never committed and a fresh clone regenerated UIDs. default.json is now
tracked; the rest of that directory stays ignored. This matters more now
that two modules generate from it.

Verified: :core:data-jvm:smoke PASS, assembleDebug green.
This commit is contained in:
Incido Developer committed 2026-10-05 18:20:59 +13:00
1 parent 8b66e82acb
commit 9fe4763aa7
13 files changed
+753 -44

No files matched your search

+87
View File
@@ -0,0 +1,87 @@
// core/data-jvm — the DESKTOP build of the same data layer the Android app
// compiles (Development Plan §6, Phase 1 milestone M1a).
//
// Shape: sibling JVM module sharing :core:data's platform-neutral sources,
// NOT one multiplatform module. Two reasons, both proven in the Phase-0
// spike (tools/DESKTOP_FEASIBILITY.md):
// 1. ObjectBox's generator cannot read Kotlin common code, so entities have
// to be compiled per-target anyway.
// 2. objectbox-android and objectbox-java ship the same io.objectbox.*
// classes; keeping them in separate modules is what stops a duplicate
// classpath clash. Each module runs its own codegen and gets its own
// MyObjectBox.
// The shared model file is copied to objectbox-models/, and regenerating in a
// second module reports "ID model file unchanged" — no UID churn.
// The ObjectBox Gradle plugin publishes no plugin marker (same reason
// :core/data/build.gradle.kts wires it through a buildscript classpath).
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath("io.objectbox:objectbox-gradle-plugin:${libs.versions.objectbox.get()}")
}
}
plugins {
alias(libs.plugins.kotlinJvm)
}
// SPIKE FINDING: `alias(libs.plugins.kotlinKapt)` fails here ("plugin is
// already on the classpath with an unknown version") because the root build
// already loads the Kotlin Gradle Plugin, which ships kapt. Applying by id
// reuses that copy.
apply(plugin = "org.jetbrains.kotlin.kapt")
apply(plugin = "io.objectbox")
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
sourceSets {
main {
kotlin.setSrcDirs(
listOf(
"build/generated/source/objectbox",
"src/main/kotlin",
// The platform-neutral data layer, compiled from :core:data's
// directory. Nothing in here may import android.*.
"../data/src/main/kotlin",
),
)
}
}
dependencies {
api(project(":core:domain"))
implementation(libs.kotlinx.coroutines.core)
// JVM counterparts of the objectbox-android the Android build uses.
implementation(libs.objectbox.java)
implementation(libs.objectbox.kotlin)
// Native database library for the build/host OS. Declared explicitly so a
// packaged desktop app knows what it must bundle (objectbox-macos /
// objectbox-windows on other platforms).
runtimeOnly(libs.objectbox.linux)
}
/**
* `./gradlew :core:data-jvm:smoke` — boots the shared data layer against a
* real ObjectBox store on the JVM and round-trips a note. Temporary until
* :desktopApp provides the real entry point (Phase 1, M1b).
*/
tasks.register<JavaExec>("smoke") {
group = "verification"
description = "Opens a JVM ObjectBox store through the shared data layer."
classpath = sourceSets["main"].runtimeClasspath
mainClass.set("org.incido.data.jvm.StoreSmokeKt")
args = listOf(layout.buildDirectory.dir("data-jvm-smoke").get().asFile.absolutePath)
}