gradle run task not working-error:--模块路径需要模块路径规范

hzbexzde  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(405)

我正试着用命令行运行gradle项目 gradle run . 我以前也做过,只需添加 application 插件并指定 mainClassName . 然而,这一次,它只是不起作用。
这是我的 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'

我得到的错误是:

$ 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

这个错误似乎暗示我需要 module-info.java . 但如果我创造 module-info.java ,我需要指定我的项目具有的每个依赖项。我觉得有一些明显的东西我错过了,但我不知道是什么。
我使用的是gradle6.7和java11。的输出 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)

的输出 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

任何帮助都将不胜感激。提前谢谢!

juzqafwq

juzqafwq1#

我解决了这个问题。我得把钥匙取下来 configuration = 'compileOnly' 我的电话线 build.gradle . 这就是最终的结果 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 {
    modules = [ 'javafx.base', 'javafx.swing', 'javafx.web' ]
}

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

我不知道为什么我决定把这一行放在第一位。javafx plugin页面提到,如果添加这一行,它将不包括本机二进制文件。

相关问题