1

我在尝试运行多模块 gradle 构建时遇到以下错误:

/Users/ashley/Personal/juggernaut/display/src/main/java/module-info.java:2: error: module not found: org.lwjgl.natives
  requires org.lwjgl.natives;
                    ^
/Users/ashley/Personal/juggernaut/display/src/main/java/module-info.java:3: error: module not found: org.lwjgl.glfw.natives
  requires org.lwjgl.glfw.natives;
                         ^
/Users/ashley/Personal/juggernaut/display/src/main/java/module-info.java:4: error: module not found: org.lwjgl.opengl.natives
  requires org.lwjgl.opengl.natives;
                           ^
/Users/ashley/Personal/juggernaut/display/src/main/java/module-info.java:5: error: module not found: org.lwjgl.stb.natives
  requires org.lwjgl.stb.natives;
                        ^
/Users/ashley/Personal/juggernaut/display/src/main/java/module-info.java:6: error: module not found: org.lwjgl.assimp.natives
  requires org.lwjgl.assimp.natives;

我的项目结构如下:

├── build.gradle
├── display
│   ├── build.gradle
│   └── src
│       └── main
│           ├── java
│           │   ├── module-info.java
├── engine
│   ├── build.gradle
│   └── src
│       └── main
│           ├── java
│           │   ├── module-info.java
└── settings.gradle

module-info.javafor需要必要的displayLWJGL3 模块:

module uk.ashleybye.juggernaut.display {
  requires org.lwjgl.natives;
  requires org.lwjgl.glfw.natives;
  requires org.lwjgl.opengl.natives;
  requires org.lwjgl.stb.natives;
  requires org.lwjgl.assimp.natives;
  exports uk.ashleybye.juggernaut.display;
}

相关依赖项包含在build.gradle

project.ext.lwjglVersion = "3.2.2"
project.ext.lwjglNatives = "natives-macos"

dependencies {
    implementation "org.lwjgl:lwjgl:$lwjglVersion"
    implementation "org.lwjgl:lwjgl-assimp:$lwjglVersion"
    implementation "org.lwjgl:lwjgl-glfw:$lwjglVersion"
    implementation "org.lwjgl:lwjgl-openal:$lwjglVersion"
    implementation "org.lwjgl:lwjgl-opengl:$lwjglVersion"
    implementation "org.lwjgl:lwjgl-stb:$lwjglVersion"
    runtimeOnly "org.lwjgl:lwjgl:$lwjglVersion:$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-assimp:$lwjglVersion:$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-glfw:$lwjglVersion:$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-openal:$lwjglVersion:$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-opengl:$lwjglVersion:$lwjglNatives"
    runtimeOnly "org.lwjgl:lwjgl-stb:$lwjglVersion:$lwjglNatives"
}

引擎requires uk.ashleybye.juggernaut.display;并具有实现依赖项:implementation project(":display").

我的版本信息:

./gradlew --version                                          Sat 17 Aug 09:31:44 2019

------------------------------------------------------------
Gradle 5.5.1
------------------------------------------------------------

Build time:   2019-07-10 20:38:12 UTC
Revision:     3245f748c7061472da4dc184991919810f7935a5

Kotlin:       1.3.31
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.14 compiled on March 12 2019
JVM:          12 (Oracle Corporation 12+33)
OS:           Mac OS X 10.14.6 x86_64

为什么gradle找不到模块?

4

1 回答 1

1

module-info.class根本不需要包括任何本地人。

删除每个 s 中的所有.nativess requires

此外,您可以压缩您的build.gradle

["", "-assimp", "-glfw", "-openal", "-opengl", "-stb"].each {
    String base = "org.lwjgl:lwjgl$it:$lwjgl_version"
    implementation base
    runtimeOnly = "$base:natives-$lwjgl_natives"
}

你可以参考我们的这个项目,它是一个多模块项目,严重依赖lwjgl,也使用JPMS。

于 2019-08-19T12:49:46.040 回答