Error during build.gradle plugin processing

Answered

Greetings!

I almost didn't work before with Java tools and environment. I made a simple “Hello World”-like application, using Java + Gradle project, which contains only one SomeClass with main() method. After I wanted to add an ObjectBox database plugin into it.

The problem is I'm getting an error: Package not found: io.objectbox

Using instruction from docs.objectbox.com I added required commands into build.gradle files (its contents below).

Reload all Gradle Projects gives me no errors. Gradle makes some work, but possibly not at all. Is it a bug, or I missed something?

The same story with Android Studio works fine.

At the root build.gradle file I added only:

buildscript {
    ext.objectboxVersion = "3.7.1"

    repositories {
        mavenCentral()
    }

    dependencies {
        classpath("io.objectbox:objectbox-gradle-plugin:$objectboxVersion")
    }
}

In /src I added second build.gradle file to put there:

plugins {
    id 'java-library'
    id 'io.objectbox'
}

dependencies {
    def objectboxVersion = "3.7.1"

    implementation("io.objectbox:objectbox-java:$objectboxVersion")
    implementation("io.objectbox:objectbox-java-api:$objectboxVersion")
    implementation("io.objectbox:objectbox-windows:$objectboxVersion")

    annotationProcessor("io.objectbox:objectbox-processor:$objectboxVersion")
}

objectbox {
    debug = true
}

Attempts to use it in Java-code like this or so:

import io.objectbox.annotation.*;
import io.objectbox.relation.*;

are giving me:

error: package io.objectbox.annotation does not exist
error: package io.objectbox.relation does not exist

But! When I point mouse cursor over import packages, it shows me Package classes.

 

0
5 comments

There seem to be a slight misconfiguration in your Project's structure: according to the Plugin developers you have to create another Project (Module) inside your existing Project.

You can do that in IDEA by right-clicking the name of your Project in Project Tool Window and selecting New → Module… that newly-created Project (Module) will have build.gradle of its own.

So your root Project's build.gradle should contain:

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

and then the nested Project's (Module's) build.gradle should contain:

plugins {
    id 'java-library'
    id 'io.objectbox'
}

dependencies {
    def objectboxVersion = "3.7.1"

    implementation("io.objectbox:objectbox-java:$objectboxVersion")
    implementation("io.objectbox:objectbox-java-api:$objectboxVersion")
    implementation("io.objectbox:objectbox-windows:$objectboxVersion")

    annotationProcessor("io.objectbox:objectbox-processor:$objectboxVersion")
}

objectbox {
    debug = true
}

 

1

No worries! The way that article is written makes it really easy to miss, especially if you have not had much experience with Gradle before.

In step (1) it mentions "root build.gradle" and then on step (2) it says “Open the build.gradle file for your app or module”.

It isn't exactly obvious, but since a Gradle Project typically only has one build.gradle, you can figure out what they were trying to say.

1

I would add:

I am using IntelliJ IDEA 2023.2.5 (Ultimate Edition). Build #IU-232.10227.8, built on November 9, 2023.
Can somebody else try to make the same blank project and add there the Objectbox plugin? Will you get the same problem?

0

Thank you so much! It is so unobvious… I lost 4 days in attempts to solve it! Now it works.

P.S. You told that “according to the Plugin developers you have to create another Project (Module) inside your existing Project.” can you point me where it is written, if it's not too much trouble? I can't find such remarks.

0

Thank you very much, Roman! I will write to Objectbox developers to improve product documentation.

0

Please sign in to leave a comment.