skip to Main Content

I’m trying to follow this tutorial.

I want to be able to write Cloud Function event triggers in my Visual Studio code Java 17 Runtime project. In the above link, there is a snippet I’m trying to copy. But I’m unable to resolve the import one error.

import com.google.events.cloud.firestore.v1.DocumentEventData; The import com.google.events cannot be resolvedJava(268435846)

The other imports, I was able to fix by modifying the pom.xml file. Below are the snippet and the current pom file. I have tried adding different dependencies on the POM file, still unable to fix it.

import com.google.cloud.functions.CloudEventsFunction;
import com.google.events.cloud.firestore.v1.DocumentEventData;
import com.google.protobuf.InvalidProtocolBufferException;
import io.cloudevents.CloudEvent;
import java.util.logging.Logger;

public class FirebaseFirestore implements CloudEventsFunction {
  private static final Logger logger = Logger.getLogger(FirebaseFirestore.class.getName());

  @Override
  public void accept(CloudEvent event) throws InvalidProtocolBufferException {
    DocumentEventData firestorEventData = DocumentEventData.parseFrom(event.getData().toBytes());

    logger.info("Function triggered by event on: " + event.getSource());
    logger.info("Event type: " + event.getType());

    logger.info("Old value:");
    logger.info(firestorEventData.getOldValue().toString());

    logger.info("New value:");
    logger.info(firestorEventData.getValue().toString());
  }
}
 <dependencies>
    <dependency>
      <groupId>com.google.cloud.functions</groupId>
      <artifactId>functions-framework-api</artifactId>
      <version>1.1.0</version>
    </dependency>
    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java</artifactId>
      <version>4.27.1</version>
    </dependency>
     <dependency>
      <groupId>com.google.firebase</groupId>
      <artifactId>firebase-admin</artifactId>
      <version>9.3.0</version>
    </dependency>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-core</artifactId>
      <version>2.39.0</version>
    </dependency>
  </dependencies>

2

Answers


  1. You could add the following codes to your pom.xml:

    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>proto-google-cloud-firestore-v1</artifactId>
      <version>1.46.0</version>
    </dependency>
    
    Login or Signup to reply.
  2. Since you’re using Java, in order to make it work, as @DazWilkin mentioned in his comment, you have to use google-cloudevent-types which is available in the Maven Repository, and then you’ll be able to import the DocumentEventData class.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search