繁体   English   中英

如何在 Eclipse 中获取我的 gradle 管理的 Java 项目以解决导入问题?

[英]How do I get my gradle-managed Java project in eclipse to resolve imports?

将我的 minecraft 插件项目迁移到新工作站后,项目构建(使用 Eclipse 中的构建),但 IDE 告诉我几乎所有项目源文件中的导入都无法解析。 如何让我的项目识别导入?

不确定它是否相关,但原始工作站/IDE 是在 OSX 10.13.6 上运行的 Eclipse Oxygen.3a 版本 (4.7.3a)。 我的新工作站运行在 Windows 10 上并使用 Eclipse 2018-12 (4.10.0) IDE。 我已经检查了几个stackoverflow帖子以寻找解决方案无济于事,尽管我怀疑这与我的项目的gradle配置有关?

两个可能的并发症是: - 我将一个 shadowjar 作为依赖项导入,该依赖项可能存在于同一目录中 - 我导入了一些外部依赖项,包括 junit-jupyter 和spongepowered.org api

这是我的 build.gradle 文件

apply plugin: 'java'
apply plugin: 'maven'


group = 'net.kevinmendoza.sedimentarysequences'
version = '0.0.1-SNAPSHOT'
description = 'Sedimentary Sequences'

sourceCompatibility = 1.8
targetCompatibility = 1.8

test {
    useJUnitPlatform()
}

repositories {
    mavenCentral()
    maven {
        name = 'sponge'
        url = 'http://repo.spongepowered.org/maven'
    }
}

dependencies {
    compile 'org.spongepowered:spongeapi:5.0.0'
    compile project(':GeoWorldLibrary')
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.0'
}

和 settings.gradle 文件

rootProject.name = 'SedimentarySequences'
include ':GeoWorldLibrary'
project(':GeoWorldLibrary').projectDir = new 
File(settingsDir,'../GeoWorldLibrary')

当我右键单击我的项目并单击 gradle>refresh dependencies 时,控制台报告“CONFIGURE SUCCESSFUL in 0s”,但是 IDE 中打开的项目仍然充斥着导入错误,这些错误应该可以从上述导入中访问。

那么,我该如何修复这个 stackoverflow?

编辑:两种类型的导入未解决错误:

the import net.<myname>.<myownprojecwhichisadependency>.mypackage.classfile cannot be resolved
the import org.spongepowered could not be resolved

我不确定这是否可以解决您的问题,但这通常对我有用:

apply plugin: 'eclipse'添加到build.gradle文件中,然后在cmd中执行命令gradlew cleanEclipse eclipse

这个问题似乎在 Eclipse 中反复出现,我正在为此苦苦挣扎。 我在 eclipse/gradle/maven 的内部没有经验,但1的答案似乎是正确的,因为我已经使用特定的 gradle 导入选项导入了我的 gradle 项目,并且每次我向 build.gradle 添加依赖项时都会遇到问题。 这次我删除了项目,并通过使用“文件->从文件系统打开项目”将其作为通用eclipse项目导入,并且导入解析问题似乎已经消退。

我希望我能提供帮助,而不仅仅是增加混乱。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM