在两个目录之一中时,Gradle无法解析Java 11模块的程序包 [英] Gradle cannot resolve package for java 11 module when in one of two directories
问题描述
我正在尝试编译包含Java和groovy混合代码的Java 11模块,并且编译不断失败,并显示以下消息:
I am trying to compile a java 11 module which contains mixed java and groovy code, and the compilation keeps failing with the following message:
包为空或不存在:my.sample.map
package is empty or does not exist: my.sample.map
我将GroovyCompile
任务更改为使用Java 11编译标志:
I changed the GroovyCompile
task to use the java 11 compilation flags:
tasks.withType(GroovyCompile) {
doFirst {
options.compilerArgs += [
'--module-path', classpath.asPath,
'-verbose',
'--module-source-path', ["$rootProject.projectDir/*/src/main/{java,groovy}/",
"$rootProject.projectDir/*/src/main/"].join(File.pathSeparator)
]
}
}
我要编译的模块具有以下文件夹结构:
I have the following folder structure for the module that I am trying to compile:
my.sample.module
└── src
├── main
│ ├── groovy
│ │ └── my
│ │ └── sample
│ │ └── map
│ │ ├── MapComponent.groovy
│ │ └── MapViewPerspective.groovy
│ ├── java
│ │ └── my
│ │ └── sample
│ │ └── map
│ │ └── config
│ │ └── MapViewConfig.java
│ ├── module-info.java
│ └── resources
│ └── MapView.fxml
└── test
module-info.java
的内容如下:
module my.sample.module {
exports my.sample.map.config;
exports my.sample.map;
requires javafx.fxml;
requires javafx.controls;
requires org.codehaus.groovy;
...
}
经过数小时的尝试来解决此问题,我唯一看到的问题是它跳过了groovy
文件夹,而仅在java
文件夹中查找内容.
After hours of trying to fix this, the only problem I can see is that it is skipping the groovy
folder and only looking for stuff in the java
folder.
然后,我尝试在java
文件夹中的程序包my.sample.map
中添加一个空类,并且编译超过了这一点,但是在groovy
文件夹中编译需要MapViewConfig
的类时失败了c3>文件夹.
Then I tried to add an empty class to the package my.sample.map
in the java
folder, and the compilation proceeds past that point but fails when compiling classes in the groovy
folder which need MapViewConfig
from the java
folder.
我做错了什么?我想我必须更新用于编译的类路径,但是我不确定要添加哪些类路径.
What am I doing wrong? I think I have to update the classpaths used for compilation, but I'm not sure which classpaths to add.
推荐答案
根据Groovy 发行说明,Groovy 3尚不支持Java模块系统,但更改正在慢慢地进行.
According to Groovy release notes, Groovy 3 does not yet have support for Java module system, but the changes are slowly making their way in.
Groovy 3正在进行更改,以允许代码库向 符合规则,并允许Groovy用户开始迁移过程. Groovy 4是我们针对完全兼容工件的目标版本,但是您可以 使用Groovy可以提前开始准备课程 3.
Groovy 3 is making changes to allow the codebase to move towards the compliant rules and allow Groovy users to begin the migration process. Groovy 4 is our target version for fully-compliant artifacts but you can start getting your classes ready ahead of time while using Groovy 3.
看起来Groovy 4是我们必须等待的黄金发行版.至少他们正在努力,所以我们只需要耐心等待.
Looks like Groovy 4 is the golden release we have to wait for. At least they are working on it, so we just have to wait patiently.
这篇关于在两个目录之一中时,Gradle无法解析Java 11模块的程序包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!