ObjectBox build.gradle

534 Views Asked by At

Trying out to use ObjectBox as java desktop database. However after following the documentation on the web site https://docs.objectbox.io/java-desktop-apps its not working. No MyObjectBox found error. I am using eclipse ide Version: 2020-09 (4.17.0), Gradle: gradle-6.7.1 ObjectBox seems not creating the model automatically after build (no model folder generated). I have created the class using the Entity annotation, build the project eclipse, nothing happens. Anyone any ideas? Works in android but not desktop. As i am not familiar with gradle project in eclipse. the following is the build file

buildscript {
    ext.objectboxVersion = '2.8.1'
    repositories {
        jcenter()
    }
    dependencies {
        classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
    }
}

apply plugin: 'java-library'
apply plugin: 'io.objectbox'

targetCompatibility = '1.8'
sourceCompatibility = '1.8'


repositories {
    jcenter()
}

dependencies {
    
    implementation "io.objectbox:objectbox-linux:$objectboxVersion"
    implementation "io.objectbox:objectbox-macos:$objectboxVersion"
    implementation "io.objectbox:objectbox-windows:$objectboxVersion"
}
apply plugin: 'io.objectbox'

dependencies {
    implementation "io.objectbox:objectbox-java:$objectboxVersion"
    annotationProcessor "io.objectbox:objectbox-processor:$objectboxVersion"
}

apply plugin: 'io.objectbox'

1

There are 1 best solutions below

2
On

Doing apply plugin: 'io.objectbox' three times does not look good. Once is enough. Please check the ObjectBox Java examples for a working setup. In your case have a closer look at the java-main example for standalone Java applications.

This is the basic structure with ... where I left out the details (check the full build.gradle file from the example):

buildscript {
...
}

apply plugin: 'java'
apply plugin: 'application'

targetCompatibility = '1.8'
sourceCompatibility = '1.8'

mainClassName = "io.objectbox.example.Main"

dependencies {
...
}

// Apply plugin after dependencies block so they are not overwritten.
apply plugin: 'io.objectbox'

Maybe checkout the example and start from there?