gpt4 book ai didi

java - Gradle多模块,子项目看不到依赖关系

转载 作者:行者123 更新时间:2023-12-01 18:32:10 25 4
gpt4 key购买 nike

项目结构如下,以MyProject为根项目,DataManager和FileManger为子项目。根项目包括子项目,DataManger 包括 FileManager。问题是 DataManager 的依赖关系不可见,所以它说。导入 DataManager 时,MyProject 也存在同样的问题。这些错误都与此类似:

C:\Users\XX\XX\XX\MyProject\DataManager\src\main\java\DataManager\DataManager.java:15: error: package org.yaml.snakeyaml is not visible
import org.yaml.snakeyaml.Yaml;
^
(package org.yaml.snakeyaml is declared in the unnamed module, but module org.yaml.snakeyaml does not read it)

.

MyProject
\build.gradle
settings.gradle
src
\main
\java
\module-info.java
MyProject
\App.java
\DataManager
\build.gradle
src
\main
\java
\module-info.java
DataManager
\DataManager.java
\FileManger
\build.gradle
src
\main
\java
\module-info.java
FileManger
\FileManger.java

我的项目构建:

plugins {
id 'java'
id 'application'
id 'groovy'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'org.beryx.jlink' version '2.12.0'
}

javafx {
version = "13"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}

mainClassName = "$moduleName/MyProject.App"

jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'MyProject'
}
}

repositories {
jcenter()
}

dependencies {
implementation 'com.google.guava:guava:28.1-jre'

testImplementation 'org.codehaus.groovy:groovy-all:2.5.8'

testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
testImplementation 'junit:junit:4.12'

compile project (':DataManager')
compile project (':FileManager')
}

application {
mainClassName = 'MyProject.App'
mainClassName = "$moduleName/MyProject.App"
}

MyProject 模块信息:

module MyProject{
requires javafx.fxml;
requires javafx.controls;
requires DataManager;

opens MyProject to javafx.fxml;
exports MyProject;
}

DataManger 构建:

plugins {
id 'java'
id 'groovy'
}

repositories {
jcenter()
}

dependencies {
implementation 'com.google.guava:guava:28.1-jre'

// Use SnakeYAML
implementation group: 'org.yaml', name: 'snakeyaml', version: '1.25'

testImplementation 'org.codehaus.groovy:groovy-all:2.5.8'

testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
testImplementation 'junit:junit:4.12'

compile project(':FileManager')
}

DataManager 模块信息:

module DataManager{
requires FileManager;
requires snakeyaml;

exports DataManager;
}

文件管理器构建:

plugins {
id 'java'
id 'groovy'
}

repositories {
jcenter()
}

dependencies {
implementation 'com.google.guava:guava:28.1-jre'

testImplementation 'org.codehaus.groovy:groovy-all:2.5.8'

testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
testImplementation 'junit:junit:4.12'
}

文件管理器模块信息:

module FileManager{
exports FileManager;
}

最佳答案

使用 Gradle 时删除 module-info.java 文件。

关于java - Gradle多模块,子项目看不到依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60142067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com