Eclipse构建版本未从gradle配置类路径-工作正常,然后中断

r1zhe5dt  于 2022-11-23  发布在  Eclipse
关注(0)|答案(1)|浏览(152)

bounty将在6天后过期。回答此问题可获得+100的声望奖励。Mike Cooper希望吸引更多人关注此问题:我永远的感激将是你的,因为这个问题是驱动我疯了!

我有一个基于Gradle的Eclipse工作区,它有一个父项目和多个子项目。Eclipse突然在将一个项目添加到另一个项目的类路径中时出现问题,尽管它在Gradle命令行中工作正常。
Eclipse显示了一个它找不到的包的典型错误:

项目

CmbProduct
+-- build.gradle
+-- settings.gradle
+--+ MangoCommon
   +-- build.gradle
   +-- src/main/java/org/mangogrove/common/util/StringTool.java
+--+ Model
   +-- build.gradle
+--+ Common
   +-- build.gradle
   +-- src/main/java/mypackage/AbstractExpander.java

项目视图:

如果我AbstractExpander.java在eclipse中打开www.example.com,它会将StringTool的导入显示为一个错误,并将“mango”包作为该错误的下划线。
我尝试过的
Model中的类可以从MangoCommon导入类。
从命令行运行“gradle compileJava”可以正常工作。
.metadata/.log中没有错误
如果我删除.metadata并重建/重新导入,问题会再次出现。
在同一个系统上为同一个产品的不同开发分支进行类似的设置可以很好地工作。
我已经从上周的备份中恢复了开发树,当它工作正常的时候,问题再次出现,只要我在Eclipse中执行Gradle -〉Sync。
我从每个项目(包括父项目)中删除了.metadata和所有.project .classpath .设置,并通过Gradle〉导入现有Gradle项目导入

编辑20221121

我在运行之前尝试了Eclipse 2021-12,我从每个项目(包括父项目)中删除了所有.metadata .project .classpath .设置,并通过Gradle〉导入现有Gradle项目导入。

编辑20221122

创建了一个全新的工作区目录,导入了git,然后运行Eclipse并执行Import〉Gradle Existing Project。同样的问题。
我在虚拟机重新启动前一周恢复了包含损坏工作区的虚拟机。Eclipse在损坏的工作区上启动正常。但是,在我运行Gradle〉Refresh Gradle Project后,它以同样的方式损坏。
我安装了eclipse 2022-06(4.20)并擦除了我的.metadata .settings .classpath .project文件。在Gradle导入现有项目后,问题马上出现了。
调查结果
在eclipse中,如果我展开Common -〉Project and External Dependencies,“MangoCommon”条目会变灰,但“Model”是正常的。

我的实际产品有许多其他的子项目,其中大部分类似于“Common”,并且在从MangoCommon导入类时显示错误。
CmbProject构建.gradle

buildscript {
    // Always load buildinfo so project.version is set as early as possible
    gradle.startParameter.taskNames = [":buildInfoLoad"] + gradle.startParameter.taskNames

    // Repos needed just for the dependencies section directly below
    repositories {
        flatDir {
            dirs 'MangoGroveGradle/repoflat'
        }
        maven { // aka "jcenter()"
            url "https://jcenter.bintray.com"
        }
    }

    dependencies {
        classpath("org.mangogrove.gradle:MangoGroveGradle:1.0.0")
    }
}

apply plugin: 'org.mangogrove.gradle'

import org.apache.tools.ant.filters.*;

allprojects {

    ext {
... snip ...
        generatedSrcDir = "src-gen
    }

wrapper {
    distributionType = Wrapper.DistributionType.BIN
}
subprojects {

    /*
     * Use "apply plugin" not "plugins" because the former allows each
     * sub-project to add their own without overriding what is set here.
     */
    apply plugin: 'java'
    /*
     * We use "testFixturesApi" and similar here so we must have this plugin
     */
    apply plugin: 'java-test-fixtures'
    // Every subproject should be configured for Eclipse
    apply plugin: 'eclipse'

    /*
     * Some files contain non-ASCII chars like Euro symbol.  We need to tell
     * Java to use UTF-8 always
     */
    compileJava {options.encoding = "UTF-8"}

    targetCompatibility = JavaVersion.VERSION_1_8
    sourceCompatibility = JavaVersion.VERSION_1_8
    javadoc.enabled = false

    sourceSets {
        main {
            java {
                // Define all source dirs - Purpose is to add "src-gen"
                srcDirs = ["src/main/java", "$rootProject.generatedSrcDir" ]
            }
        }
    }
    /*
     * Tell Gradle to treat src-gen like a resource so it will copy <model>.ecore files here
     * and set classpath properly at runtime.
     */
    sourceSets.main.resources.srcDir "$rootProject.generatedSrcDir"

    repositories {
        maven {
            // Local repo for annovention
            url uri("$rootDir/MangoCommon/repo")
        }
        maven {
            url uri("$rootDir/logbackwela/repo")
        }

        mavenCentral()
        maven { url "https://maven.java.net/content/groups/public" }
        // Texo/EMF
        maven { url "https://oss.sonatype.org/content/groups/public" }
        // Eclipse
        maven { url "https://oss.sonatype.org/content/repositories/public/eclipse" }
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
        maven { url 'https://mvnrepository.com/artifact' }
        
        maven { url "https://repository.jboss.org/nexus/content/groups/public-jboss" }
        maven { url "https://maven.vaadin.com/vaadin-addons"    }
        maven { url "https://oss.sonatype.org/content/repositories/vaadin-snapshots"    }
        
        maven { url "https://maven.clapper.org" }
        // Project Lombok
        maven { url "https://projectlombok.org/mavenrepo" }
    }

    def bouncycastleVersion = "1.69" // Was 1.68
    def lombokVersion = "1.18.20" // was 1.18.10
    .... snip ...

    ext {
        springFrameworkVersion = "5.3.6" // 5.3.4
        springDataVersion = "2.4.8" // 2.4.3
        ... snip ...
    }

    configurations.all {
        // We use logback now but some dependencies pull in slf4j-jdk14 so we exclude here
        exclude group:"org.slf4j", module: "slf4j-jdk14"
    }

    dependencies {
        /*
         * PRODUCT SPECIFIC
         */
        implementation "org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion"
        implementation "org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion"
        testFixturesApi "org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion"
        testFixturesApi "org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion"

        /*
         * Common and product
         */
        implementation "org.simpleframework:simple-xml:$simpleXmlVersion"
        /*
         * We use logback for logging but need various slf4j packages to route other
         * logger frameworks to slf4j which is handled by logback
         */
        implementation "ch.qos.logback:logback-classic:$logbackVersion"
        implementation "org.slf4j:slf4j-api:$slf4jVersion"
        // Janino required by our logback configs
        implementation "org.codehaus.janino:janino:$janinoVersion"
        // Route JCL -> slf4j which forwards to logback
        implementation "org.slf4j:jcl-over-slf4j:$slf4jVersion"
        // Route JUL -> slf4j which forwards to logback
        // This is required for c3p0 to use slf4j -> logback
        implementation "org.slf4j:jul-to-slf4j:$slf4jVersion"
        // Route log4j -> slf4j which forwards to logback
        implementation "org.slf4j:log4j-over-slf4j:$slf4jVersion"
        // Send slf4j to log4j 1.2 for those JARs which use slf4j
        //implementation "org.slf4j:slf4j-log4j12:$slf4jVersion"
        // Log4j itself
        //implementation "log4j:log4j:$log4jVersion"

        // Texo (use changing: true to enable snapshots)
        implementation group: "org.eclipse.emf", name: "org.eclipse.emf.texo", version: "$texoVersion", changing: true
        implementation group: "org.eclipse.emf", name: "org.eclipse.emf.texo.server", version: "$texoVersion", changing: true
        implementation group: "org.eclipse.emf", name: "org.eclipse.emf.texo.xml", version: "$texoVersion", changing: true
        // Texo dependencies (not automaticly added by texo)
        implementation "org.eclipse.emf:org.eclipse.emf.common:$emfVersion"
        implementation "org.eclipse.emf:org.eclipse.emf.ecore:$emfVersion"
        implementation "org.eclipse.emf:org.eclipse.emf.ecore.xmi:$emfVersion"
        implementation "org.jsoup:jsoup:$jsoupVersion"

        // Apache HTTP client
        implementation("org.apache.httpcomponents:httpclient:$apacheHttpClientVersion") {
            // This is an older implementation deprecated by jcl-over-slf4j
            exclude group: "commons-logging"
        }
        // EventBus and more
        implementation "com.google.guava:guava:$googleGuavaVersion"
        testFixturesApi "com.google.guava:guava:$googleGuavaVersion"

        implementation("com.sun.mail:javax.mail:$javaxMailVersion") {   // Actual implementation
            // This dependency includes an older version
            exclude group: "javax.activation"
        }
        // Make sure we use the same version for everything
        implementation "jakarta.annotation:jakarta.annotation-api:1.3.5"

        implementation "net.java.dev.jna:jna:$jnaVersion"
        implementation "net.java.dev.jna:jna-platform:$jnaVersion"

        // This package provided by Tomcat or Servlet container
        compileOnly "javax.servlet:javax.servlet-api:$javaxServletVersion"
        testFixturesApi "javax.servlet:javax.servlet-api:$javaxServletVersion"

        annotationProcessor                 "org.projectlombok:lombok:$lombokVersion"
        compileOnly                         "org.projectlombok:lombok:$lombokVersion"
        testFixturesApi                     "org.projectlombok:lombok:$lombokVersion"
        testFixturesAnnotationProcessor     "org.projectlombok:lombok:$lombokVersion"
        testImplementation                  "org.projectlombok:lombok:$lombokVersion"
        testAnnotationProcessor             "org.projectlombok:lombok:$lombokVersion"

        testImplementation "org.testng:testng:$testngVersion"
    }
}

CmbProject设置.gradle

include 'CodeGen'
include 'MangoCommon'
include 'Model'
include 'Common'

普通建筑.平地

plugins {
    id 'java-library'
}

// Enable deprecation messages in javac
compileJava {
    options.compilerArgs << '-Xlint:deprecation'
}
compileTestJava {
    options.compilerArgs << '-Xlint:deprecation'
}

dependencies {
    api project(":Model")

    // Version does not change
    api "javax.xml.soap:javax.xml.soap-api:1.4.0"

    testImplementation testFixtures(project(":MangoCommon"))
    testFixturesApi project(":MangoCommon")
    testFixturesApi testFixtures(project(":MangoCommon"))

    // Required for JAX-RS Client
    api "org.glassfish.jersey.core:jersey-client:$jerseyGlassfishVersion"
    // Required by client + servlet container 2.26 and later [RUNTIME REQUIREMENT]
    api "org.glassfish.jersey.inject:jersey-hk2:$jerseyGlassfishVersion"
    // Required by Client jersey 2.26 and later [RUNTIME REQUIREMENT]
    api "org.glassfish.jersey.media:jersey-media-jaxb:$jerseyGlassfishVersion"
}
... snip out tasks ....

模型构建.gradle

plugins {
    id 'java-library'
}
compileJava.dependsOn copyEcore

// Enable deprecation messages in javac
compileJava {
    options.compilerArgs << '-Xlint:deprecation'
}

dependencies {
    api project(":MangoCommon")
//  testImplementation testFixtures(project(":MangoCommon"))

    api "org.flywaydb:flyway-core:$flywayVersion"
    // Provide javax.persistence classes
    api "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final"
    implementation "org.hibernate:hibernate-core:$hibernateVersion"
}

sourceSets.test.resources.srcDir "src/dev/resources" // for persistconfig.properties
... snip tasks ...

Mango普通建筑.gradle

plugins {
    id 'java-library'
}

// Enable deprecation messages in javac
compileJava {
    options.compilerArgs << '-Xlint:deprecation,unchecked'
}
compileTestJava {
    options.compilerArgs << '-Xlint:deprecation,unchecked'
}
compileTestFixturesJava {
    options.compilerArgs << '-Xlint:deprecation'
}

dependencies {
    testImplementation "org.testng:testng:$testngVersion"

    api "com.impetus:annovention:$annoventionVersion"

    api("org.clapper:javautil:$clapperJavaUtilVersion") {
        // Exclude older asm to avoid implementation issue
        exclude group: "asm", module: "asm"
        exclude group: "asm", module: "asm-commons"
        exclude group: "asm", module: "asm-tree"
        // Exclude items provided elsewhere
        exclude group: "javax.mail", module: "mail"
        exclude group: "commons-logging", module: "commons-logging"
        exclude group: "javax.activation"
    }

    api("org.freemarker:freemarker:$freemarkerVersion") {
        exclude group: "freemarker", module: "freemarker" // Legacy org-less group
    }
    
    implementation "org.hibernate:hibernate-core:$hibernateVersion"
    testFixturesApi "org.hibernate:hibernate-core:$hibernateVersion"
    
    api "org.springframework:spring-core:$springFrameworkVersion"
    api "org.springframework:spring-context:$springFrameworkVersion"
    api "org.springframework:spring-context-support:$springFrameworkVersion"
    api "org.springframework:spring-orm:$springFrameworkVersion"
    api "org.springframework:spring-web:$springFrameworkVersion"
    api "org.springframework:spring-webmvc:$springFrameworkVersion"
    api "org.springframework.data:spring-data-jpa:$springDataVersion"
    api "com.zaxxer:HikariCP:$hikariCpVersion"
}
... snip tasks ...

以下是Eclipse -〉Gradle同步创建的Common/.classpath:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
        <classpathentry kind="src" output="bin/main" path="src/main/java">
                <attributes>
                        <attribute name="gradle_scope" value="main"/>
                        <attribute name="gradle_used_by_scope" value="main"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" output="bin/main" path="src-gen">
                <attributes>
                        <attribute name="gradle_scope" value="main"/>
                        <attribute name="gradle_used_by_scope" value="main"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" output="bin/main" path="src/main/resources">
                <attributes>
                        <attribute name="gradle_scope" value="main"/>
                        <attribute name="gradle_used_by_scope" value="main"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" output="bin/test" path="src/test/java">
                <attributes>
                        <attribute name="gradle_scope" value="test"/>
                        <attribute name="gradle_used_by_scope" value="test"/>
                        <attribute name="test" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" output="bin/test" path="src/test/resources">
                <attributes>
                        <attribute name="gradle_scope" value="test"/>
                        <attribute name="gradle_used_by_scope" value="test"/>
                        <attribute name="test" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" output="bin/testFixtures" path="src/testFixtures/java">
                <attributes>
                        <attribute name="gradle_scope" value="testFixtures"/>
                        <attribute name="gradle_used_by_scope" value="testFixtures"/>
                        <attribute name="test" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
        <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
        <classpathentry kind="src" path="/Model">
                <attributes>
                        <attribute name="without_test_code" value="false"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" path="/MangoCommon">
                <attributes>
                        <attribute name="without_test_code" value="false"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="output" path="bin/default"/>
</classpath>

环境状况

eclipse.buildId=4.25.0.I20220831-1800
java.version=17.0.4.1
java.vendor=Eclipse Adoptium
Gradle: 7.5.1
Buildship: 3.1.6
fnvucqvd

fnvucqvd1#

发现问题了!
Gradle 7.5.x + Buildship 3.1.6似乎坏了。当我配置Eclipse(首选项〉Gradle〉特定版本)使用7.4.2时,一切又恢复了正常。
我通常将Eclipse Gradle配置为使用Gradle Package 器。一个月前,我通过命令行将Gradle Package 器从7.4.2升级到了7.5.1。Gradle在命令行运行正常,但在我的开发系统重新启动后,我运行了Gradle〉Refresh Gradle Project,这是我第一次在Eclipse中使用7.5.1。

相关问题