Gradle run task not working - Error: --module-path requires module path specification

Viewed 1509

I'm trying to run my Gradle project from the command line using gradle run. I've done this in the past, and it was as simple as adding the application plugin and specifying the mainClassName. However, this time, it just won't work.

Here's my build.gradle:

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java Library project to get you started.
 * For more details take a look at the Java Libraries chapter in the Gradle
 * User Manual available at https://docs.gradle.org/6.3/userguide/java_library_plugin.html
 */

plugins {
    // Apply the java-library plugin to add support for Java Library
    id 'java-library'
    id 'org.openjfx.javafxplugin' version '0.0.9'
    id 'application'
}

repositories {
    // Use jcenter for resolving dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

dependencies {
    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:28.2-jre'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'
    
    // BEGIN CUSTOM DEPENDENCIES //
    
    // jsoup HTML parser library @ https://jsoup.org/
    compile 'org.jsoup:jsoup:1.13.1'

    // https://mvnrepository.com/artifact/com.zenjava/javafx-maven-plugin
    compile group: 'com.zenjava', name: 'javafx-maven-plugin', version: '8.8.3'
    
    
    // Spark - used for the server
    compile "com.sparkjava:spark-core:2.9.3"
    
    // slf4j-simple, used for server output
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.30'
    
    // slf4j-api, used for server output
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
    
    // org.json, used to send data to the front end
    compile group: 'org.json', name: 'json', version: '20200518'
    
    // java-string-similarity, used to calculate Levenshtein distance to sort results
    compile group: 'info.debatty', name: 'java-string-similarity', version: '2.0.0'
    
    
}

javafx {
    version = '11'
    modules = [ 'javafx.base', 'javafx.controls', 'javafx.swing', 'javafx.graphics', 'javafx.media', 'javafx.web' ]
    configuration = 'compileOnly'
}

mainClassName = 'io.gitlab.hasanger.searchengine.SearchEngineServer'

And here's the error I get:

$ gradle run

> Configure project :
Project : => no module-info.java found

> Task :run FAILED
Error: --module-path requires module path specification

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command '/usr/lib/jvm/java-11-openjdk-amd64/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1s
4 actionable tasks: 3 executed, 1 up-to-date

The error seems to imply that I need to create module-info.java. But if I create module-info.java, I'll need to specify every single dependency my project has. I feel like there's something obvious I'm missing, but I can't figure out what.

I'm using Gradle 6.7 and Java 11. Output of java -version:

openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)

Output of gradle -version:

------------------------------------------------------------
Gradle 6.7
------------------------------------------------------------

Build time:   2020-10-14 16:13:12 UTC
Revision:     312ba9e0f4f8a02d01854d1ed743b79ed996dfd3

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          11.0.8 (Ubuntu 11.0.8+10-post-Ubuntu-0ubuntu120.04)
OS:           Linux 5.4.0-48-generic amd64

Any help would be greatly appreciated. Thanks in advance!

1 Answers

I fixed the problem. I had to remove the configuration = 'compileOnly' line from my build.gradle. This is what the final build.gradle looks like:

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java Library project to get you started.
 * For more details take a look at the Java Libraries chapter in the Gradle
 * User Manual available at https://docs.gradle.org/6.3/userguide/java_library_plugin.html
 */

plugins {
    // Apply the java-library plugin to add support for Java Library
    id 'java-library'
    id 'org.openjfx.javafxplugin' version '0.0.9'
    id 'application'
}

repositories {
    // Use jcenter for resolving dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

dependencies {
    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:28.2-jre'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'
    
    // BEGIN CUSTOM DEPENDENCIES //
    
    // jsoup HTML parser library @ https://jsoup.org/
    compile 'org.jsoup:jsoup:1.13.1'

    // https://mvnrepository.com/artifact/com.zenjava/javafx-maven-plugin
    compile group: 'com.zenjava', name: 'javafx-maven-plugin', version: '8.8.3'
    
    // Spark - used for the server
    compile "com.sparkjava:spark-core:2.9.3"
    
    // slf4j-simple, used for server output
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.30'
    
    // slf4j-api, used for server output
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
    
    // org.json, used to send data to the front end
    compile group: 'org.json', name: 'json', version: '20200518'
    
    // java-string-similarity, used to calculate Levenshtein distance to sort results
    compile group: 'info.debatty', name: 'java-string-similarity', version: '2.0.0'
    
}

javafx {
    modules = [ 'javafx.base', 'javafx.swing', 'javafx.web' ]
}

mainClassName = 'io.gitlab.hasanger.searchengine.SearchEngineServer'

I'm not sure why I decided to include that line in the first place. The JavaFX plugin page mentions that if this line is added, it won't include native binaries.

Related