Home > Mobile >  How to "require" module "gwt.user" On Java, JDK17, "module-info.java",
How to "require" module "gwt.user" On Java, JDK17, "module-info.java",

Time:05-01

I am trying to keep up with the new changes in Java, one step a time.
I am updating my old libraries with module-info.java files.
I have a very simple project named "api-clone" dependent on "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>

With the module-info.java below:

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

When netbeans runs compile, it builds successfully:

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\1.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\1.0-SNAPSHOT\api-clone-1.0-SNAPSHOT.pom
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time:  2.315 s
Finished at: 2022-04-28T19:32:22 03:00
------------------------------------------------------------------------

However, when I look at the module-info.java file, Netbeans show error: enter image description here

  • Is it because "gwt.user" is not a module-ized project?
  • How to handle that kind of projects, when ones projects are dependent on them?

CodePudding user response:

As @skomisa answered, the problem I am facing in "module-info.java"
can be solved in "pom.xml" by adding exclusion on dependecy tag.

<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>
  • Related