Skip to content
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

Gradle option to use model file instead of creating/modifying one #1050

Open
sezaru opened this issue Feb 13, 2022 · 1 comment
Open

Gradle option to use model file instead of creating/modifying one #1050

sezaru opened this issue Feb 13, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@sezaru
Copy link

sezaru commented Feb 13, 2022

Currently, every time someone builds a Gradle project, the plugin will look for the entities and recreate the model JSON file if needed.

My suggestion is to add an option to only read the model file without checking and changing it.

The reason for such an option is to allow sharing the same model file and database in multiple languages.

To be more specific, I have a Flutter app that uses objectbox-dart, that app also has Android widgets written in Kotlin, so the idea is that I want to load an objectbox database in read-only mode inside my widget to get information previously added using objectbox-dart in Flutter.

I'm able to do that if I add this to my build.gradle file:

        javaCompileOptions {
            annotationProcessorOptions {
                arguments.put("objectbox.modelPath", "$rootDir/../lib/objectbox-model.json".toString())
            }
        }

And that works, the issue is that from the Flutter side, I have multiple entities, but from the Kotlin side, I'm only interested in one, so if I build my grade project, my JSON model will be replaced with only the entity shared between both languages, to make the Flutter app work again, I need to always forcefully regenerate the model so it overrides what the gradle plugin changed. Hence why I want to prevent gradle build from changing that file.

@sezaru sezaru added the enhancement New feature or request label Feb 13, 2022
@greenrobot-team
Copy link
Member

Thanks for the suggestion! Interesting use case.

This is not as simple as adding a read-only flag as the plugin also generates code that depends on entity classes to exist. Technically it should be possible, as only the model (MyObjectBox) needs to be generated fully to be passed to the database on open. Other generated classes (EntityInfo_ and EntityCursor) could be skipped in such a mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants