找不到模块 OpenJDK 12 Maven Eclipse

module not found OpenJDK 12 Maven Eclipse

环境:OpenJDK 12、Maven 3.6.1、Eclipse 4.12,模块是同一工作区中的 2 个独立项目。

上下文: 我正在尝试编译 2 个简单的模块。

问题: 消息-> 编译第二个模块时找不到模块


第一个模块:


public class Car{
    //Strings attributes
    public Car(args){
      //set args
    }
    //getter & setters
}
module ModuleCars {
    exports com.org.car; //the class is inside this package
}

POM:

 <modelVersion>4.0.0</modelVersion>
  <groupId>cars</groupId>
  <artifactId>ModuleCars</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>12</release>
                </configuration>
            </plugin>
        </plugins>
  </build>

运行 Maven 清理编译:好的


第二个模块:


public class CarFactory  {

       private static CarFactory instance;
        private CarFactory() {          
        }
        public static synchronized CarFactory getInstance() {
            if(instance == null) {
                instance = new CarFactory();
            }
            return instance;
        }
        public Car createCar() {
            return new Car("5","Red","01/01/2019");
        }
}

module ModuleFactory {
    requires transitive ModuleCar;
    exports com.org.factory; //the class is inside this package
}

Pom:

<modelVersion>4.0.0</modelVersion>
  <groupId>factory</groupId>
  <artifactId>ModuleFactory</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>12</release>
                </configuration>
            </plugin>
        </plugins>
  </build>

项目属性: -> Java 构建路径 -> 项目 -> 模块路径 -> 添加 ModuleCars

运行 Maven: 清理编译:未找到模块:ModuleCars

更新 1: 模块之间的连接是使用 Eclipse(使用模块路径)进行的,这是我找到的唯一方法。

在你的第二个模块中添加第一个模块作为依赖项:

<dependencies>
  <dependency>
     <groupId>cars</groupId>
     <artifactId>ModuleCars</artifactId>
     <version>0.0.1-SNAPSHOT</version>
  </dependency>
</dependencies>

并且您必须使用全新安装来安装您的第一个模块。