[英]How do I get my gradle-managed Java project in eclipse to resolve imports?
After migrating a minecraft plugin project of mine to a new workstation, the project builds (with buildship in Eclipse) but the IDE is telling me nearly every import in my projects source files can't be resolved.将我的 minecraft 插件项目迁移到新工作站后,项目构建(使用 Eclipse 中的构建),但 IDE 告诉我几乎所有项目源文件中的导入都无法解析。 How do I get my project to recognize the imports?
如何让我的项目识别导入?
Not sure if its relevant, but the original workstation/IDE was Eclipse Oxygen.3a release (4.7.3a) running on OSX 10.13.6.不确定它是否相关,但原始工作站/IDE 是在 OSX 10.13.6 上运行的 Eclipse Oxygen.3a 版本 (4.7.3a)。 My new workstation is on Windows 10 and uses the Eclipse 2018-12 (4.10.0) IDE.
我的新工作站运行在 Windows 10 上并使用 Eclipse 2018-12 (4.10.0) IDE。 I have checked several stackoverflow posts for a solution to no avail, although I suspect it has something to do with the gradle configuration for my project?
我已经检查了几个stackoverflow帖子以寻找解决方案无济于事,尽管我怀疑这与我的项目的gradle配置有关?
Two possible complications are: - I import a shadowjar as a dependency which presumably exists in the same directory - I import some external dependencies including junit-jupyter and the spongepowered.org api两个可能的并发症是: - 我将一个 shadowjar 作为依赖项导入,该依赖项可能存在于同一目录中 - 我导入了一些外部依赖项,包括 junit-jupyter 和spongepowered.org api
Here's my build.gradle file这是我的 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'
}
and the settings.gradle file和 settings.gradle 文件
rootProject.name = 'SedimentarySequences'
include ':GeoWorldLibrary'
project(':GeoWorldLibrary').projectDir = new
File(settingsDir,'../GeoWorldLibrary')
When I right click my project and click gradle>refresh dependencies, the console reports a "CONFIGURE SUCCESSFUL in 0s", however the opened project in the IDE is still riddled with import errors which should be accessible from the above imports.当我右键单击我的项目并单击 gradle>refresh dependencies 时,控制台报告“CONFIGURE SUCCESSFUL in 0s”,但是 IDE 中打开的项目仍然充斥着导入错误,这些错误应该可以从上述导入中访问。
So, how do I go about fixing this stackoverflow?那么,我该如何修复这个 stackoverflow?
Edit: the two types of imports not resolved errors:编辑:两种类型的导入未解决错误:
the import net.<myname>.<myownprojecwhichisadependency>.mypackage.classfile cannot be resolved
the import org.spongepowered could not be resolved
I'm not sure if this fixes your problem, but this often works for me: 我不确定这是否可以解决您的问题,但这通常对我有用:
Add apply plugin: 'eclipse'
to your build.gradle file and then execute command gradlew cleanEclipse eclipse
in cmd. 将
apply plugin: 'eclipse'
添加到build.gradle文件中,然后在cmd中执行命令gradlew cleanEclipse eclipse
。
This problem seems to be recurrent with Eclipse and I am one struggling with it.这个问题似乎在 Eclipse 中反复出现,我正在为此苦苦挣扎。 I am not experienced in the internals of eclipse/gradle/maven but the answer to 1 seems to be right because I had imported my gradle project by using the specific gradle importing option and got the problem everytime I added dependencies to build.gradle.
我在 eclipse/gradle/maven 的内部没有经验,但1的答案似乎是正确的,因为我已经使用特定的 gradle 导入选项导入了我的 gradle 项目,并且每次我向 build.gradle 添加依赖项时都会遇到问题。 This time I deleted the project and imported it as a generic eclipse project by using "File -> Open Project from file system" and the importing resolution problems seem to have subsided.
这次我删除了项目,并通过使用“文件->从文件系统打开项目”将其作为通用eclipse项目导入,并且导入解析问题似乎已经消退。
I hope I am helping and not just adding to the confusion.我希望我能提供帮助,而不仅仅是增加混乱。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.