javaeclipsemavengmail-apimodule-info

module-info.java imports can't be resolved for Gmail API


I am trying to use the java module-info file with my project. The project uses Java15+, Maven & JavaFX. I've added a class to handle the sending of an email with attachment through the Gmail API.

The code worked successfully in a test project that did not use modules, but I am running into an issue when trying to bring the code into my main project.

I have added "requires" fields for the new libraries, but there are some imports that will not resolve. Namely:

com.google.api.client.googleapis.auth.oauth2
com.google.api.client.googleapis.javanet
com.google.api.client.googleapis.json

I have exhausted my googling ability on this issue, perhaps I am not looking for the correct solution. I am new to using modules. Any advice or suggestions will be welcome.

My module-info.java :

    module maven.javafx.hs_doc_gen.HS_Doc_Gen_11 {
        requires javafx.controls;
        requires javafx.fxml;
        requires javafx.swing;
    requires java.sql;
    requires java.desktop;
    requires org.apache.pdfbox;
    requires activation;
    requires mail;
    requires com.google.api.services.gmail;
    requires com.google.api.client;
    requires com.google.api.client.json.gson;
    requires com.google.api.client.extensions.jetty.auth;
    requires org.apache.commons.codec;
    requires com.google.api.client.auth;
    requires com.google.api.client.extensions.java6.auth;
    
    opens maven.javafx.hs_doc_gen.HS_Doc_Gen_11 to javafx.fxml;
    opens gui to javafx.fxml;
    exports maven.javafx.hs_doc_gen.HS_Doc_Gen_11;
    exports gui;
}

My pom.xml :

        <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>maven.javafx.hs_doc_gen</groupId>
    <artifactId>HS_Doc_Gen_11</artifactId>
    <version>0.0.2</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>15</maven.compiler.source>
        <maven.compiler.target>15</maven.compiler.target>
    </properties>
    <dependencies>

        <!-- JavaFX -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>21</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>21</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>21</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>21</version>
        </dependency>

        <!-- Apache PDF Box -->
        <dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>pdfbox</artifactId>
            <version>2.0.26</version>
        </dependency>

        <!-- MySQL -->
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <version>8.2.0</version>
        </dependency>

        <!-- Gmail API with JavaMail -->
        <dependency>
            <groupId>com.google.oauth-client</groupId>
            <artifactId>google-oauth-client-jetty</artifactId>
            <version>1.34.1</version>
        </dependency>
        <dependency>
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.apis</groupId>
            <artifactId>google-api-services-gmail</artifactId>
            <version>v1-rev20220404-2.0.0</version>
        </dependency>

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>
        <!--        
        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.6.2</version> 
        </dependency>
        -->

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>15</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running -->
                        <!-- Usage: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                             <mainClass>
                                                          maven.javafx.hs_doc_gen.HS_Doc_Gen_11.App
                                                         </mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Platform: Windows 11 IDE: Eclipse Version: 2024-03 (4.31.0) Build id: 20240307-1437 Java: JDK21

I tried adding the modules individually. Modules I tried to add:

com.google.api.client.googleapis
com.google.api.client.googleapis.auth
com.google.api.client.googleapis.auth.oauth2
com.google.api.client.googleapis.javanet
com.google.api.client.googleapis.json

I get the error "* cannot be resolved to a module"

When trying to "clean install" with Maven, I receive errors saying that the modules are not visible and that the main package does not read it, which is understandable based on the above.


Solution

  • I needed to add requires google.api.client;

    I was confused as the module-info.java already included com.google.api.client, but this didnt cover the packages I needed.