【发布时间】:2019-01-25 18:40:48
【问题描述】:
我使用 gradle 创建了一个带有 intelliJ 的 java 10 项目。 我将一些东西复制到其中(使用库 guava 和 javaFx 的一些“AppFx”类,以及个人 build.gradle 文件)。 我还在 src/main/java 中添加了一个 module-info.java 文件,内容如下:
module biblio5.main {
requires javafx.graphics;
requires javafx.controls;
requires javafx.base;
requires guava;
}
其中 grava 是一个自动模块。
这里是 build.gradle 的相关部分:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.guava:guava:23.0'
}
intelliJ 可以编译项目(使用类似锤子的图标),但是当我从 intelliJ 运行 compileJava gradle 任务时,出现错误:
13:12:46:正在执行任务“compileJava”...
任务:compileJava FAILED C:\Users\lolve\Documents\gradle_java\biblio5\src\main\java\module-info.java:5: 错误:找不到模块:番石榴 需要番石榴; ^ 1 个错误
我在网上花了很多时间,但没有找到答案。
谢谢
ps:这里是整个 build.gradle:
buildscript {
dependencies {
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
classpath 'eu.appsatori:gradle-fatjar-plugin:0.3'
}
repositories {
maven {url "https://mvnrepository.com/artifact/de.dynamicfiles.projects.gradle.plugins/javafx-gradle-plugin"}
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
jcenter()
}
}
plugins {
id 'java'
id 'application'
id 'edu.sc.seis.launch4j' version '2.4.4'
}
apply plugin: 'javafx-gradle-plugin'
apply plugin: 'eu.appsatori.fatjar'
group 'lorry'
version '1'
sourceCompatibility = 1.10
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
maven {url "https://mvnrepository.com/artifact/de.dynamicfiles.projects.gradle.plugins/javafx-gradle-plugin"}
jcenter()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.guava:guava:23.0'
}
//********************************************************************************************
launch4j {
outfile='bibliotek-v3.exe'
mainClassName = 'lorry.AppFx'
icon = "${projectDir}\\icons\\hands2.ico"
copyConfigurable = project.tasks.fatJar.outputs.files
//jar = "lib/${project.tasks.fatJar.archiveName}"
//headerType = "console"
jar = "${buildDir}\\productFatJar\\fat.jar"
}
jar {
baseName = 'executable3'
version = ''
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'lorry.AppFx'
)
}
}
task copyExecutable(type: Copy) {
from file("${buildDir}\\launch4j\\bibliotek-v3.exe")
into file("c:\\Users\\lolve\\Documents\\gradle_java\\produits")
}
task copyJar(type: Copy) {
from file("${buildDir}\\jfx\\app\\bibliotek-v3.jar")
into file("c:\\Users\\lolve\\Documents\\gradle_java\\produits")
}
task copyFatJar(type: Copy) {
from file("${buildDir}\\productFatJar\\fat.jar")
into file("c:\\Users\\lolve\\Documents\\gradle_java\\produits")
}
createExe.doLast{
tasks.copyExecutable.execute()
}
task createJar(){
doLast{
tasks.jfxJar.execute()
tasks.jfxNative.execute()
tasks.copyJar.execute()
}
}
jfx {
jfxMainAppJarName = "bibliotek-v3.jar"
// minimal requirement for jfxJar-task
mainClass = 'lorry.AppFx'
// minimal requirement for jfxNative-task
vendor = 'lolveley'
}
fatJar {
destinationDir=file("${buildDir}\\productFatJar")
archiveName="fat.jar"
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'lorry.AppFx'
)
}
}
task createFats(){
doLast{
tasks.fatJar.execute()
tasks.copyFatJar.execute()
tasks.createExe.execute()
}
}
编辑
好吧,我进行了更改,现在我在 module-info.java 中有“com.google.commons”而不是番石榴,但我仍然收到此错误:
测试开始于 14:20 ... 14:20:14:正在执行任务“检查”...
任务:compileJava FAILED C:\Users\lolve\Documents\gradle_java\biblio5\src\main\java\module-info.java:5: 错误:找不到模块:com.google.common 需要 com.google.common; ^ 1 个错误
我将 intelliJ 中的 gradle(默认选项 - 推荐 - 是“默认 gradle wrapper”)更改为我的本地 gradle(v4.9),但没有任何效果。 “与java兼容”是什么意思?尝试安装 java 9 怎么样?
【问题讨论】:
-
Gradle 在编译/运行时默认使用 classpath,而不是 modulepath。我相信这会导致您的问题。见Building Java 9 Modules。不幸的是,根据该链接,Gradle still 没有对 Jigsaw 模块的一流支持(截至 4.10-rc-2)。
-
我的回答不好,我假设 gradle(如果更新)将与 Java9+ 模块化代码的模块路径兼容。仅通过上述文档的概述,this 应该是要研究的部分之一
-
谢谢你,Slaw & nullpointer,添加短代码使它工作。我无法将答案标记为已接受,因为只有评论,但如果将其作为答案,我很快就会将其标记为已接受。
标签: java gradle intellij-idea guava java-module