java: cannot access com.google.auth.Credentials class file for com.google.auth.Credentials not found?

I am trying to implement firestore in my maven project. But I'm getting this error: "java: cannot access com.google.auth.Credentials class file for com.google.auth.Credentials not found" I've found a post on stackoverflow with the same problem but I don't know exactly what they mean.

This is the code where I try to connect with my database

package Game.service;

import com.google.api.core.ApiFuture;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.firestore.FieldValue;
import com.google.cloud.firestore.Firestore;
import com.google.cloud.firestore.WriteResult;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.cloud.FirestoreClient;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Objects;

public class FireBaseInitializer {
    Firestore database;
    public com.google.cloud.firestore.Firestore getDatabase() {
        return database;
    }

    public void initializeFirestore() throws IOException {

        String fileName = "key.json";

        ClassLoader classLoader = Firestore.class.getClassLoader();
        File file = new File(Objects.requireNonNull(classLoader.getResource(fileName)).getFile());
        FileInputStream serviceAccount = new FileInputStream(String.valueOf(file.toPath()));

        FirebaseOptions options = new FirebaseOptions.Builder()
                .setCredentials(GoogleCredentials.fromStream(serviceAccount))
                .setDatabaseUrl("https://tock-47444.firebaseio.com")
                .build();

        FirebaseApp.initializeApp(options);

        com.google.cloud.firestore.Firestore firestoreDatabase = FirestoreClient.getFirestore();


        database = firestoreDatabase;
    }
}

This is the exact error that I'm getting

C:\Users\Moeme\Documents\School\HsLeiden\Propodeuse\P4\PROJECT\keezen-IIPSENE\src\main\java\Game\service\FireBaseInitializer.java:32:50
java: cannot access com.google.auth.Credentials
  class file for com.google.auth.Credentials not found

This is line 32

.setCredentials(GoogleCredentials.fromStream(serviceAccount))

Here are the dependencies

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>15</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>15</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>15</version>
        </dependency>
        <dependency>
            <groupId>com.google.firebase</groupId>
            <artifactId>firebase-admin</artifactId>
            <version>7.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
        </dependency>
    </dependencies>


Read more here: https://stackoverflow.com/questions/67925943/java-cannot-access-com-google-auth-credentials-class-file-for-com-google-auth-c

Content Attribution

This content was originally published by Moemen Hussein at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: