Gradle实现不能与JavaFX一起工作



我正在尝试做一些有趣的Java项目,以提高编码水平。目前,我正在尝试用JavaFX和Gradle做一个离线的本地密码管理器。

为了安全起见,我想要一种方法来散列密码,然后将其存储在文件中。之前,我在Android应用程序中使用了Google的Guava库,因为它有一些很好的散列功能,所以我想我也会在这个项目中使用它。不幸的是,我不能访问任何Guava的api/对象。

我的settings.gradle文件

plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.10'
id 'org.beryx.jlink' version '2.24.1'
}
group 'me.tisleo'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
google()
}
ext {
junitVersion = '5.8.1'
}
sourceCompatibility = '17'
targetCompatibility = '17'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
application {
mainModule = 'me.tisleo.jpasswordmanager'
mainClass = 'me.tisleo.jpasswordmanager.JPasswordManager'
}
javafx {
version = '18-ea+6'
modules = ['javafx.controls', 'javafx.fxml']
}
dependencies {
implementation('org.controlsfx:controlsfx:11.1.0')
implementation('org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0')
implementation("com.google.guava:guava:31.1-jre")
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")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'app'
}
}
jlinkZip {
group = 'distribution'
}

guava文档简单地说要将实现implementation("com.google.guava:guava:31.1-jre")添加到我的settings.gradle文件中,所以我这样做了。每当我尝试使用库时,例如使用Hashing类,它看起来像Hashing.sha256().hashString(myString, StandardCharsets.UTF_8), IntelliJ说无法解析符号"散列"。

我不确定我做错了什么。我已经确保重新加载Gradle,甚至尝试手动将Guava文件添加到我的项目结构中。

您有一个模块化的项目,因此您需要在module-info.java文件中包含以下行来访问番石榴API:

requires com.google.common;

对于当前的guava发行版(31.1-jre),该模块名是在META-INF/MANIFEST.MF文件中的jar文件中通过以下行定义的:

Automatic-Module-Name: com.google.common

最新更新