【发布时间】:2021-12-10 09:00:34
【问题描述】:
项目结构如下图所示:
tictactoe-server-infrastructure 模块有一个名为libs 的文件夹,其中包含两个带有一些库代码的 jar 文件。在build.gradle 模块的build.gradle 文件的dependencies 部分中,我有下一行implementation fileTree(include: ['*.jar'], dir: 'libs'),它允许gradle 识别该jar 文件中的类并在tictactoe-server-infrastructure 模块中使用它们的类。
当我想将tictactoe-server-infrastructure 模块作为对tictactoe-server-presentation 模块的依赖项添加时,我将implementation project(':tictactoe-server-infrastructure') 行放入build.gradle 文件的dependencies 块中,用于tictactoe-server-presentation 模块。
当我尝试构建一个项目时,它构建得很好,没有任何错误。
但是,一旦我尝试在 tictactoe-server-presentation 模块中使用该 jar 文件中的任何类,这些类意味着作为与 tictactoe-server-infrastructure 模块的依赖项添加,IDEA 似乎无法识别它们并且 gradle 将不再构建项目.
我已经尝试过使缓存无效并重新启动、重新导入 gradle 项目并删除 gradle 缓存。我还尝试将两个 jars 添加为全局库,并通过 IDEA 的项目结构菜单将它们添加到 tictactoe-server-presentation,但我想像以前一样完全从 gradle 中完成。
奇怪的是,在另一个具有较旧 gradle 版本的项目中,我使用了 compile 方法,并且它起作用了。
tictactoe-server-infrastructure build.gradle
plugins {
id 'java'
}
group 'com.ttt'
version '0.1.0'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.20'
testCompileOnly 'org.projectlombok:lombok:1.18.20'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
implementation fileTree(include: ['*.jar'], dir: 'libs')
}
tictactoe-server-presentation build.gradle
plugins {
id 'java'
}
group 'com.ttt'
version '0.1.0'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation project(':tictactoe-server-infrastructure')
compileOnly 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.20'
testCompileOnly 'org.projectlombok:lombok:1.18.20'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
}
【问题讨论】:
标签: java gradle intellij-idea