javamavengoogle-cloud-platformcloud-document-ai

Cannot Import Google Cloud


I am following Google's official tutorial on setting up Document AI: https://cloud.google.com/document-ai/docs/libraries#client-libraries-install-java

My POM file:

    <project>
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.mycompany.app</groupId>
        <artifactId>my-app</artifactId>
        <version>1</version>
    
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>com.google.cloud</groupId>
                    <artifactId>libraries-bom</artifactId>
                    <version>26.1.3</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
                <dependency>
                    <groupId>com.google.cloud</groupId>
                    <artifactId>google-cloud-document-ai</artifactId>
                    <version>2.7.5</version>
                </dependency>
            </dependencies>
        </dependencyManagement>
    
    </project>

But I cannot get the imports to show up properly:

enter image description here


Solution

  • dependencyManagement should contain only the bom, other dependencies should be under dependencies, one more point, you should not have the version for google-cloud-document-ai because its version should come from the bom.

    example pom.xml below

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>io.github.ozkanpakdil</groupId>
        <artifactId>gcloud-ai</artifactId>
        <version>1.0-SNAPSHOT</version>
        <name>gcloud-ai</name>
    
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>com.google.cloud</groupId>
                    <artifactId>libraries-bom</artifactId>
                    <version>26.29.0</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
    
        <dependencies>
            <dependency>
                <groupId>com.google.cloud</groupId>
                <artifactId>google-cloud-document-ai</artifactId>
            </dependency>
        </dependencies>
    </project>
    

    Reference: