Home > Software engineering >  Gradle implementations not working with JavaFX
Gradle implementations not working with JavaFX

Time:07-03

I am trying to do some fun Java projects on the side to get better at coding. Currently, I'm trying to do an offline, local password manager with JavaFX and Gradle.

I wanted a way to hash a password, for security, and then store it in a file. Previously, I used Google's Guava library in an Android App because it had some good hashing capabilities, so I thought I would use it in this project too. Unfortunately, I can't access any of Guava's APIs/objects.

This is my settings.gradle file

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'
}

The guava documentation simply said to add the implementation implementation("com.google.guava:guava:31.1-jre") to my settings.gradle file, so I did. Whenever I try to use the library, for e.g. using the Hashing class, which would look something like Hashing.sha256().hashString(myString, StandardCharsets.UTF_8), IntelliJ says "Cannot resolve symbol 'Hashing'".

I'm not sure what I'm doing wrong. I've made sure to reload Gradle, and even tried manually adding the Guava files to my Project Structure.

CodePudding user response:

You have modular project, so you need to include the following line in your module-info.java file to access the guava API:

requires com.google.common;
  • Related