如何在 Java、JDK17、"module-info.java"、Netbeans、Maven 上 "require" 模块 "gwt.user"

How to "require" module "gwt.user" On Java, JDK17, "module-info.java", Netbeans, Maven

我正在努力跟上 Java 中的新变化,一步一个脚印。
我正在用 module-info.java 文件更新我的旧库。
我有一个非常简单的项目,名为“api-clone”,依赖于“gwt-user”。
pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.tugalsan</groupId>
    <artifactId>api-clone</artifactId>
    <version>1.0-SNAPSHOT</version>
  
    <dependencies>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-user</artifactId>
            <version>2.9.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    
    <build>
        <resources> 
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.java</include>
                    <include>**/*.gwt.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </resource>
        </resources>
        
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>3.2.1</version>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <phase>package</phase>
                            <goals>
                                <goal>jar-no-fork</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
            </plugin>
        </plugins>
    </build>
    
    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

使用以下模块-info.java:

open module com.tugalsan.api.clone {
    requires gwt.user;
}

netbeans 运行编译时,构建成功:

cd C:\me\codes\GWT\api\api-clone; "JAVA_HOME=C:\Program Files\Eclipse Adoptium\jdk-17.0.2.8-hotspot" cmd /c "\"C:\Program Files\NetBeans-13\netbeans\java\maven\bin\mvn.cmd\" \"-Dmaven.ext.class.path=C:\Program Files\NetBeans-13\netbeans\java\maven-nblib\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 clean install"
Scanning for projects...

-----------------------< com.tugalsan:api-clone >-----------------------
Building api-clone 1.0-SNAPSHOT
--------------------------------[ jar ]---------------------------------

--- maven-clean-plugin:2.5:clean (default-clean) @ api-clone ---
Deleting C:\me\codes\GWT\api\api-clone\target

--- maven-resources-plugin:2.6:resources (default-resources) @ api-clone ---
Using 'UTF-8' encoding to copy filtered resources.
Copying 4 resources
Copying 0 resource

--- maven-compiler-plugin:3.10.1:compile (default-compile) @ api-clone ---
Required filename-based automodules detected: [gwt-user-2.9.0.jar]. Please don't publish this project to a public artifact repository!
Changes detected - recompiling the module!
Compiling 3 source files to C:\me\codes\GWT\api\api-clone\target\classes

--- maven-resources-plugin:2.6:testResources (default-testResources) @ api-clone ---
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory C:\me\codes\GWT\api\api-clone\src\test\resources

--- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ api-clone ---
Changes detected - recompiling the module!

--- maven-surefire-plugin:2.12.4:test (default-test) @ api-clone ---

--- maven-jar-plugin:2.4:jar (default-jar) @ api-clone ---
Building jar: C:\me\codes\GWT\api\api-clone\target\api-clone-1.0-SNAPSHOT.jar

--- maven-install-plugin:2.4:install (default-install) @ api-clone ---
Installing C:\me\codes\GWT\api\api-clone\target\api-clone-1.0-SNAPSHOT.jar to C:\Users\tugal\.m2\repository\com\tugalsan\api-clone.0-SNAPSHOT\api-clone-1.0-SNAPSHOT.jar
Installing C:\me\codes\GWT\api\api-clone\pom.xml to C:\Users\tugal\.m2\repository\com\tugalsan\api-clone.0-SNAPSHOT\api-clone-1.0-SNAPSHOT.pom
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time:  2.315 s
Finished at: 2022-04-28T19:32:22+03:00
------------------------------------------------------------------------

但是,当我查看 module-info.java 文件时,Netbeans 显示错误:

正如@skomisa 回答的那样,我在“module-info.java”中面临的问题
可以在“pom.xml”中通过在依赖标签上添加排除来解决。

<dependencies>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <exclusions>
            <exclusion>
                <groupId>javax.validation</groupId>
                <artifactId>validation-api</artifactId>
            </exclusion>
        </exclusions>
        <version>2.9.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

有用的视频:https://www.youtube.com/watch?v=xKmv24_2Asw&t=2094s