Repository navigation
Support Gradle build cache #1114
Description
Activity
Thanks for reporting! I guess the culprit is that the model file is only touched by the annotation processor. We need to check if it can somehow be indicated to Gradle that the processor has the model file as an input and output.
Also likely the generated code as output (or is it already?).The generated code is created using theFilerAPI, where output is monitored by Gradle.A workaround could be to add the model file as an input to e.g. an assemble task (or whichever necessary):
tasks.named("assembleDebug") { inputs.property("objectboxModel") { file("objectbox-models/default.json") } }Maybe we can also do this automatically with the Gradle plugin.
(Somewhat related, though configuration cache other than build cache is still experimental: #948)
- changed the title
[-]Duplicate index ID at runtime[/-][+]Support Gradle build cache[/+]on Feb 13, 2023 Thanks for your reply!
I am not a Gradle expert, but it looks like a working solution (I'm using Kotlin Scripts here):
plugins { id("io.objectbox") // ... } // ... tasks.withType<org.jetbrains.kotlin.gradle.tasks.BaseKapt>().configureEach { inputs.file("objectbox-models/default.json") }I added the model file as an input for
BaseKapttask. Now every change in the model file causes thekaptDebugKotlintask to rerun as expected!

Maybe we can also do this automatically with the Gradle plugin.
I think it's a good idea!
@Raseri Thanks for testing this! Looks like adding an input to the kapt (or Java equivalent annotation processor) task is what we will let the Gradle plugin do then.
For our reference, this is internal issue
objectbox-java#174Reacted by Alexander Surinov and LukeWhile researching something related, I noticed that kapt also has an option to turn off build cache for itself exactly for this reason.
So as an alternative to configuring the model JSON file as an input like suggested above (and if done correctly also as output, which may lead to further issues), it should also be possible to use this workaround:
kapt { useBuildCache = false }hey @greenrobot-team @alexsurinov would objectbox/objectbox-java-generator#12 be acceptable to close this issue?
@soloturn Thanks, but these generated pull requests without actual knowledge of the project aren't really helpful.
The bug is occurred in an Android Project.
Description of the bug
During a manual conflict resolution, the
objectbox-models/default.jsonfile may accidentally contain duplicatedindexIdentries. During the build time, we don't have any errors. The project builds successfully, and the build output is cached to the Gradle Build Cache. Only at runtime, when we buildBoxStoreinstance, an error occurred:io.objectbox.exception.DbSchemaException: Duplicate index ID 2 found for property .... Moreover, when a developer fixes duplicatedindexIdentries in theobjectbox-models/default.jsonfile and rebuilds the project, the error is still in place due to the result of the previous build is used from the Gradle Build Cache. It incurs hard-to-debug problems for our dev team.Basic info:
Steps to reproduce the behavior:
org.gradle.caching=truein thegradle.propertiesfile.UserandCompany) with the uniquenameproperty.objectbox-models/default.jsonfile.objectbox-models/default.jsonfile: set the same value to bothindexIdentries (Company.nameandUser.name).io.objectbox.exception.DbSchemaException: Duplicate index ID 2 found for property ...indexIdin theobjectbox-models/default.jsonfile.Expected behavior
Duplicate index IDerror should occur during the build time, not at runtime.objectbox-models/default.jsonfile should lead to the invalidation of the Gradle Build Cache to prevent the usage of stale data from the previous build.Code
I've prepared the demo project to reproduce the problem with the described above steps:
https://github.com/rAseri/ObjectBoxDemo
Logs, stack traces