我有一个相对简单的模块化项目,并且我已经设置了我在文档以及How to force gradle to add dependencies to the module path instead of the class path in eclipse?等不同答案或文章中找到的所有选项。
我得到一个找不到模块的异常:
java.lang.module.FindException: Module gdx.backend.lwjgl not found, required by com.myproject.client只有在通过gradle的应用程序运行我的应用程序时,我才会得到这个异常:run task。当我在IntelliJ中运行它或使用Badass JLink插件生成的运行时映像时,一切都运行得很好。经过几个小时的调试和手动构建命令行,我能够弄清楚正确启动的程序与gradle所做的不同之处在于,其他所有程序都使用--module-path选项启动程序,而Gradle坚持生成以下命令行,无论我在build.gradle文件中做什么:
Starting process 'command 'C:\Tools\java\bin\java.exe''. Working directory: C:\repos\pv-core\master\pv-client Command: C:\Tools\java\bin\java.exe -Dfile.encoding=windows-1252 -Duser.country=FR -Duser.language=fr -Duser.variant -cp C:\Users\accou\.gradle\caches\modules-2\files-2.1\com.badlogicgames.gdx\gdx-backend-lwjgl\1.9.11\3c094feb74e2aef14e30e988326612ee75387c8f\gdx-backend-lwjgl-1.9.11.jar;[...] --module com.myproject.client/com.myproject.client.ClientStarter
Successfully started process 'command 'C:\Tools\java\bin\java.exe''
Error occurred during initialization of boot layer
java.lang.module.FindException: Module gdx not found, required by com.myproject.client我的gradle文件包含以下内容:
根文件:
subprojects {
apply plugin: "java"
java {
modularity.inferModulePath = true
}
targetCompatibility = '11'
sourceCompatibility = '11'
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
test {
useJUnitPlatform()
testLogging {
events 'PASSED', 'FAILED', 'SKIPPED'
}
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
}
version = '0.0.1'
ext {
appName = 'MyProject'
gdxVersion = '1.9.11'
box2DLightsVersion = '1.4'
aiVersion = '1.8.0'
artemisVersion = '2.3.0'
junitVersion = '5.4.2'
slf4jVersion = '1.8.0-beta2'
}
}
project(':pv-core') {
dependencies {
}
}客户端项目(应用程序):
plugins {
id 'org.beryx.jlink' version '2.22.3'
id 'application'
}
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher{
name = 'hello'
jvmArgs = ['-Dlog4j.configurationFile=./log4j2.xml']
}
}
ext.moduleName = 'com.myproject.client'
group = 'com.myproject.client'
//mainClassName = 'com.myproject.client.PVClientStarter'
application {
mainModule = 'com.myproject.client'
mainClass = 'com.myproject.client.ClientStarter'
}
apply plugin: 'java-library'
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
api "com.esotericsoftware.spine:spine-libgdx:3.6.53.1"
api "com.underwaterapps.overlap2druntime:overlap2d-runtime-libgdx:0.1.0"
api "com.kotcrab.vis:vis-ui:1.3.0"
api "net.dermetfan.libgdx-utils:libgdx-utils:0.13.4"
//api "de.tomgrill.gdxfacebook:gdx-facebook-core:1.4.1"
//api "de.tomgrill.gdxdialogs:gdx-dialogs-core:1.2.5"
api "com.github.czyzby:gdx-kiwi:1.9.1.9.6"
api "com.github.czyzby:gdx-lml:1.9.1.9.6"
api "com.github.czyzby:gdx-lml-vis:1.9.1.9.6"
api "de.golfgl.gdxgamesvcs:gdx-gamesvcs-core:1.0.2"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
//compile "com.esotericsoftware:kryo:5.0.0"
compile "kryonet:kryonet:2.21"
testCompile 'org.testng:testng:7.3.0'
}
test {
useTestNG()
//testLogging.showStandardStreams = true
testLogging {
events "passed", "skipped", "failed"
}
}
compileJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs += [
'--module-path', classpath.asPath
]
classpath = files()
}
}关于我如何(最终)告诉gradle使用--module-path而不是-cp ?!
发布于 2020-11-24 05:48:45
我想我是随机算出来的。我一直在处理gradle文件,并最终删除了包含语句modularity.inferModulePath = true的java块(尽管这是gradle文档中给出的主要建议...!),将compileJava块上移到依赖项和jlink插件配置之上,最终以某种方式结束了工作。
在这些东西中包含了很多黑魔法,这是我在几天的vs模块和gradle tbh战斗后留下的感觉。
编辑:实际上我没有解决问题的根本原因,gradle仍然通过模块路径使用-cp,但我在上面描述的更改最终导致gradle成功地启动了我的应用程序,但仍然使用了-cp选项。因此,我仍然对gradle进行适当的、符合JPMS的模块启动(而不是类路径启动)非常感兴趣。
发布于 2021-07-15 17:21:29
为处理Java中的模块而引入的Gradle模型是基于推断当前项目代码是否是模块的。
这意味着您的应用程序需要在其清单中包含module-info或Automatic-Module-Name条目。
有关更多详细信息,请参阅documentation。
https://stackoverflow.com/questions/64974974
复制相似问题