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

时间:2018-05-26 11:39:37

标签: java eclipse gradle

我正在使用Eclipse Oxygen中的Gradle项目使用Java 8和Gradle包装器4.6。

当我尝试添加新的依赖项compile 'com.googlecode.json-simple:json-simple:1.1.1'并刷新项目时,所有“项目和外部依赖项”文件夹都消失而没有跟踪,这会阻止我的项目从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中的一个问题。

2 个答案:

答案 0 :(得分:1)

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

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

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

最适合我的修补程序是关闭Eclipse,然后运行

gradlew cleanEclipse eclipse

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

答案 1 :(得分:0)

重构项目名称时,我也遇到了这个问题。

以下步骤解决了我的问题:

  1. import os import subprocess from csv import writer from csv import reader # path to googleidlist.csv csvfile = 'c:\\GAM\\googleidlist.csv' destination = 'c:\\GAM\\OUTPUT\\' #Destination for downloaded documents # Open the input_file in read mode and output_file in write mode with open(csvfile, 'r') as read_obj, \ open('output_1.txt', 'w', newline='') as write_obj: # Create a csv.reader object from the input file object csv_reader = reader(read_obj) # Create a csv.writer object from the output file object csv_writer = writer(write_obj) # Read each row of the input csv file as list for row in csv_reader: file_id = row[0] outcome = subprocess.Popen(['gam', 'user', 'googleserviceaccountname', 'get', 'drivefile', 'id', file_id, 'targetfolder',destination], stdout=subprocess.PIPE) # os.system("gam user david.bruinsma@colonialmed.com show fileinfo "+ file_id + "name") filename = subprocess.Popen(['gam', 'user', 'googleserviceaccountname', 'show', 'fileinfo', file_id, 'name' ], stdout=subprocess.PIPE) output = outcome.stdout.readline() file_name = filename.stdout.readline() print(output) # Append the default text in the row / list # row.append(filename) row.append(output) row.append(file_name) row.append(file_id) # Add the updated row / list to the output file csv_writer.writerow(row) 插件添加到eclipse
  2. 右键单击build.gradle,选择build.gradle,然后选择gradle

只有refresh gradle project对我没有帮助。