0

考虑到 Java 1.9 现在已经发布了一段时间,我仍然对使用 eclipse 和 buildship 启动和运行 1.9 项目有多么困难感到惊讶。

我现在花了 2 天时间试图让这架飞机飞起来,而且走了很远,但一个问题是我只是没有起步:

最重要的是 build.gradle 文件中的整个“eclipse.classpath.file.whenMerged”内容(我的文件见下文)。

因此,我的问题有两个:

  1. 我是否错过了一些让 Gradle 和 buildship 的拼图支持更容易的东西?
  2. 我该怎么做才能不手动修补命令行(如上面的链接中所述)?

由于我目前正在为我的团队评估 Eclipse/Gradle/Buildship 的支持,我需要解决第二个问题。否则我团队中的开发人员会发疯的。因此,我也在考虑离开 Eclipse。

附带问题:其他 IDE 对模块和 Gradle 的支持有多好?

我在用

  • Eclipse 2020-12 (4.18.0.v20201202-1800)
  • Gradle 3.1.4.v20200326-1743 的 Eclipse 插件
  • 爪哇 12
  • 6.7.1 年级

谢谢

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java library project to get you started.
 * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
 * User Manual available at https://docs.gradle.org/6.7.1/userguide/building_java_projects.html
 */

plugins {
    // Apply the java-library plugin for API and implementation separation.
    id 'java-library'
    id 'eclipse'
    id 'application'
}

sourceCompatibility = targetCompatibility = '1.12'

repositories {
    // Use JCenter for resolving dependencies.
    jcenter()
}

dependencies {
    // Use JUnit test framework.
    testImplementation 'junit:junit:4.13'

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'org.postgresql:postgresql:42.2.18'
}

java {
    modularity.inferModulePath = true
}


application {
    mainModule = 'com.myproduct.mod.lib' // name defined in module-info.java
    mainClass = 'com.myproduct.mod.lib.Library'
}


eclipse {
    classpath {
        
        file {
            whenMerged {
                //Define a module as being either a library or a project dependency.
                //Test sources are excluded because eclipse wants them on the classpath for some reason (1)
                entries.findAll {  (it instanceof org.gradle.plugins.ide.eclipse.model.Library || it instanceof org.gradle.plugins.ide.eclipse.model.ProjectDependency) && !it.entryAttributes.get('gradle_used_by_scope').equals('test') }.each {
                    it.entryAttributes['module'] = 'true'
                }
                
                //Test-scoped stuff should set the appropriate flag
                entries.findAll { (it.properties.kind.equals('src') || it.properties.kind.equals('lib')) && it.entryAttributes.get('gradle_used_by_scope').equals('test') }.each {
                    it.entryAttributes['test'] = 'true'
                }
                
                entries.findAll { isConGradle(it) }.each {
                  it.entryAttributes['module'] = 'true'
                }
            }
        }
    }
}

boolean isConGradle(entry) {
  entry.kind == 'con' && entry.path == 'org.eclipse.buildship.core.gradleclasspathcontainer'
}
4

0 回答 0