【发布时间】:2023-01-10 12:18:02
【问题描述】:
我正在 IntelliJ 中使用 JavaFX 创建一个示例演示应用程序,但我需要使用一个名为 JavaFaker 库的库。我使用 Gradle 作为构建系统,但每次我尝试添加库时,无论是作为 build.gradle 文件中的实现,还是通过 IntelliJ 项目结构选项,module.java 文件都会显示错误:找不到模块。我已经尝试将它添加到模块中,但没有任何变化。
模块信息.java
module com.example.demo1 {
requires javafx.controls;
requires javafx.fxml;
requires javafaker;
opens com.example.demo1 to javafx.fxml;
exports com.example.demo1;
}
构建.gradle
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.10'
id 'org.beryx.jlink' version '2.24.1'
}
group 'com.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
ext {
junitVersion = '5.8.2'
javaFakerVersion = '1.0.2'
}
sourceCompatibility = '17'
targetCompatibility = '17'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
application {
mainModule = 'com.example.demo1'
mainClass = 'com.example.demo1.HelloApplication'
}
javafx {
version = '17.0.1'
modules = ['javafx.controls', 'javafx.fxml']
}
dependencies {
implementation("com.github.javafaker:javafaker:${javaFakerVersion}")
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}
test {
useJUnitPlatform()
}
jlink {
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip") as RegularFile
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'app'
}
}
jlinkZip {
group = 'distribution'
}
错误信息
> Task :HelloApplication.main() FAILED
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafaker not found, required by com.example.demo1
【问题讨论】:
-
编辑,你现在可以帮忙吗?
-
您的 Gradle 构建脚本没有定义对
javafaker库的依赖。 -
我删除了它,因为我的 module.info 给了我一个工具提示,上面写着“模棱两可的模块引用:javafaker”
-
您肯定需要在依赖项中声明的 javafaker 库。放回去。
-
再次将 javafaker 添加到 gradle 文件中。
标签: java gradle intellij-idea javafx