java - Eclipse Gradle项目突然失去依赖

标签 java eclipse gradle

我正在使用 Java 8 和 Gradle wrapper 4.6 在 Eclipse Oxygen 中处理一个 Gradle 项目。

当我尝试添加新的依赖项compile 'com.googlecode.json-simple:json-simple:1.1.1' 并刷新项目时,所有“Project and External Dependencies”文件夹消失得无影无踪,这使我的项目无法从 Eclipse 运行(尽管它可以通过 Gradle Run 任务运行)。

去掉新添加的依赖并不能救我。 gradlew cleanEclipse & gradlew eclipse 也没有无数次刷新项目。

我还尝试清除缓存并在重新导入时强制重建项目,但没有显示“项目和外部依赖项”。

我应该怎么做才能恢复旧的依赖项?

这是我的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 }
}

编辑: 切换到 IntelliJ 后,问题解决了(我使用了项目的同一个文件夹)。所以我认为这是 Eclipse 中的一个问题。

最佳答案

我也遇到了“项目和外部依赖项”文件夹消失的问题。它显示为“org.eclipse.buildship.core.gradleclasspathcontainer”。

如果您没有看到该行,则需要将其添加到 .classpath 文件中。

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

对我有用的修复方法是关闭 Eclipse,然后运行

gradlew cleanEclipse eclipse

然后打开 Eclipse 并将 Gradle 特性添加到项目中。

关于java - Eclipse Gradle项目突然失去依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50542347/

相关文章:

java - 正则表达式检查IP

java - 当我尝试从 Activity 类调用函数时崩溃

linux - 自动完成在 Eclipse 中根本不起作用

java - Ant 在 Eclipse Kepler 中不工作(Java 虚拟机启动器 - 发生 Java 异常)

android - UnsupportedMethodException Android Studio 0.8.9

android - 如何使用 gradle 构建项目?

android - Buck - 构建具有多种 Gradle 风格/构建类型和 list 的 Android 应用程序

java - 具有继承调用的构造函数中的最终变量

java - ListView 未加载,在 textview.setText() 上返回 null 对象;

eclipse - Grails 3开发IDE的设置