首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >分级运行任务不能工作.错误:.模块路径要求模块路径规范

分级运行任务不能工作.错误:.模块路径要求模块路径规范
EN

Stack Overflow用户
提问于 2020-11-15 01:02:18
回答 1查看 1.7K关注 0票数 2

我正在尝试使用gradle run从命令行运行我的Gradle项目。我过去就这样做过,它很简单,比如添加application插件和指定mainClassName。然而,这一次,它就是行不通。

这是我的build.gradle

代码语言:javascript
运行
复制
/*
 * 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'

我得到的错误是:

代码语言:javascript
运行
复制
$ 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,我需要指定我的项目所具有的每个依赖项。我觉得有明显的东西我错过了,但我不知道是什么。

我使用的是Gradle 6.7和Java11。java -version的输出

代码语言:javascript
运行
复制
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输出

代码语言:javascript
运行
复制
------------------------------------------------------------
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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-15 12:12:01

我解决了问题。我不得不将configuration = 'compileOnly'行从我的build.gradle中删除。最后的build.gradle是这样的:

代码语言:javascript
运行
复制
/*
 * 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插件页面提到,如果添加了这一行,它将不包含本机二进制文件。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64840271

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档