Search code examples
javamavenquarkusquarkus-panache

java.lang.ClassNotFoundException: javax.inject.Provider - Quarkus


This is my Publisher object:


import io.quarkus.hibernate.orm.panache.PanacheEntity;

import jakarta.persistence.Entity;
import java.time.Instant;

@Entity
public class Publisher extends PanacheEntity {

    // ======================================
    // =             Attributes             =
    // ======================================

    public String name;

    public Instant createdDate = Instant.now();

    // ======================================
    // =           Constructors             =
    // ======================================

    public Publisher(String name) {
        this.name = name;
    }

    public Publisher() {
    }

    @Override
    public String toString() {
        return "Publisher{" +
                "name='" + name + '\'' +
                ", createdDate=" + createdDate +
                ", id=" + id +
                '}';
    }
}

This is my test:


import io.quarkus.test.TestTransaction;
import io.quarkus.test.junit.QuarkusTest;
import org.agoncal.quarkus.panache.model.Publisher;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@QuarkusTest
public class PublisherRepositoryTest {
    @Test
    @TestTransaction
    public void shouldCreateAndFindPublisher() {
        Publisher publisher = new Publisher("name");

        publisher.persist(publisher);
        assertNotNull(publisher.id);

        publisher = publisher.findById(publisher.id);
        assertEquals("name", publisher.name);

    }

}

This is the error when doing a mvn clean install:

-------------------------------------------------------------------------------
Test set: org.agoncal.quarkus.panache.repository.PublisherRepositoryTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 3.755 s <<< FAILURE! - in org.agoncal.quarkus.panache.repository.PublisherRepositoryTest
org.agoncal.quarkus.panache.repository.PublisherRepositoryTest.shouldCreateAndFindPublisher  Time elapsed: 0.002 s  <<< ERROR!
java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/inject/Provider
Caused by: java.lang.NoClassDefFoundError: javax/inject/Provider
Caused by: java.lang.ClassNotFoundException: javax.inject.Provider

I think the error is quite weird, because I do not use javax in my code...


Solution

  • As @geoand pointed out of me I'm moving my comment as answer for future readers.

    vintage-store is still using Quarkus 2.x branch as opposite as other projects are using Quarkus 3.