简体   繁体   English

Eclipse Gradle 项目中依赖项突然丢失

[英]Sudden loss of dependencies in Eclipse Gradle project

I'm working with a Gradle project in Eclipse Oxygen with Java 8 and Gradle wrapper 4.6.我正在使用 Java 8 和 Gradle 包装器 4.6 在 Eclipse Oxygen 中处理 Gradle 项目。

When i tried to add a new dependency compile 'com.googlecode.json-simple:json-simple:1.1.1' and refresh the project, all the "Project and External Dependencies" folder disappeared without a trace, which stops my project running from Eclipse (it can run through Gradle Run task though).当我尝试添加新的依赖项compile 'com.googlecode.json-simple:json-simple:1.1.1'并刷新项目时,所有“项目和外部依赖项”文件夹都消失得无影无踪,这使我的项目停止运行来自 Eclipse(虽然它可以通过 Gradle Run 任务运行)。

Removing the newly added dependency does not save me.删除新添加的依赖项并不能拯救我。 Neither gradlew cleanEclipse & gradlew eclipse nor refreshing the project countless times. gradlew cleanEclipse & gradlew eclipse没有刷新项目无数次。

I also attempted to clear the cache and forced project to rebuild when reimport, but no "Project and External Dependencies" shows up.我还尝试在重新导入时清除缓存并强制项目重建,但没有显示“项目和外部依赖项”。

What should i do to bring back the old dependencies?我应该怎么做才能恢复旧的依赖项?

Here is my build.gradle这是我的build.gradle

// Apply the java plugin to add support for Java
apply plugin: 'java'
// Apply the plugin to be runnable
apply plugin: 'application'
// Apply the eclipse plugin to import project on other machines
apply plugin: 'eclipse'
// JUnit 5
apply plugin: 'org.junit.platform.gradle.plugin'

// Define the entry point
mainClassName = 'meshIneBits.MeshIneBitsMain'
applicationName = 'MeshIneBits'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

sourceCompatibility = 1.8

// In this section you declare the dependencies for your production and test code
dependencies {
    compile 'org.processing:core:3.3.5'
    compile 'org.jogamp.jogl:jogl-all:2.3.2'
    compile 'org.jogamp.gluegen:gluegen-rt:2.3.2'

    runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-linux-amd64"
    runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-linux-armv6"
    runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-linux-armv6hf"
    runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-linux-i586"
    runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-macosx-universal"
    runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-windows-amd64"
    runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-windows-i586"

    runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-linux-amd64"
    runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-linux-armv6"
    runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-linux-armv6hf"
    runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-linux-i586"
    runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-macosx-universal"
    runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-solaris-i586"
    runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-windows-amd64"
    runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-windows-i586"

    testCompile('org.junit.jupiter:junit-jupiter-api:5.1.0',
            'org.junit.jupiter:junit-jupiter-params:5.1.0')
    testRuntime('org.junit.jupiter:junit-jupiter-engine:5.1.0',
            'org.junit.platform:junit-platform-launcher:1.1.0')
}

eclipse {
    project.natures 'org.eclipse.buildship.core.gradleprojectnature'
    classpath {
        file {
            defaultOutputDir = file('bin/main')
            whenMerged {
                //change output folder for tests
                def testsrc = entries.find { it.path == 'src/test/java' }
                testsrc.output = "bin/test"

                def testres = entries.find { it.path == 'src/test/resources' }
                testres.output = "bin/test"

                // Remove local ref for libs
                entries.removeAll{ it.kind == "lib" }
            }
            containers 'org.eclipse.jdt.junit.JUNIT_CONTAINER/5', 'org.eclipse.buildship.core.gradleclasspathcontainer' }
    }
}

buildscript {
    repositories { mavenCentral() }
    dependencies { classpath 'org.junit.platform:junit-platform-gradle-plugin:1.1.0' }
}

jar {
    baseName = applicationName
    version = '0.2.0'
    manifest { attributes  'Main-Class' : mainClassName }
}

Edit: After switching to IntelliJ, the problem is solved (i used the same folder of project).编辑:切换到 IntelliJ 后,问题解决了(我使用了与项目相同的文件夹)。 So i think this is a problem in Eclipse.所以我认为这是 Eclipse 中的一个问题。

I also had this problem where the "Project and External Dependencies" folder disappeared.我也遇到了“项目和外部依赖项”文件夹消失的问题。 It instead showed as 'org.eclipse.buildship.core.gradleclasspathcontainer'.它显示为“org.eclipse.buildship.core.gradleclasspathcontainer”。

If you do not see that line, then it needs to be added to the .classpath file.如果您没有看到该行,则需要将其添加到 .classpath 文件中。

<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer" />

The fix that worked for me was closing Eclipse, and running对我有用的修复是关闭 Eclipse,然后运行

gradlew cleanEclipse eclipse

then opening Eclipse and adding the Gradle nature to the project.然后打开 Eclipse 并将 Gradle 性质添加到项目中。

I also encountered this problem when I refactor the project name.我在重构项目名称的时候也遇到过这个问题。

Following steps solve my problem:以下步骤解决了我的问题:

  1. add eclipse plugin to build.gradleeclipse插件添加到build.gradle
  2. right click build.gradle , choose gradle then select refresh gradle project右键单击build.gradle ,选择gradle然后选择refresh gradle project

only refresh gradle project didn't help me.只有refresh gradle project对我没有帮助。

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

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