[英]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.