首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Eclipse构建不配置gradle工作的类路径,然后崩溃。

Eclipse构建不配置gradle工作的类路径,然后崩溃。
EN

Stack Overflow用户
提问于 2022-11-18 03:03:55
回答 1查看 69关注 0票数 0

我有一个基于gradle的eclipse工作区,它有一个父项目和多个子项目。Eclipse突然出现了向另一个类路径添加项目的问题,尽管它在gradle命令行中运行得很好。

Eclipse显示了一个它找不到的包的典型错误:

项目

代码语言:javascript
复制
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

项目意见:

如果我在eclipse中打开AbstractExpander.java,它会将StringTool的导入显示为一个错误,并将"mango“包作为错误。(见第一张图)。

我试过的

从MangoCommon导入类的模型中的类很好。

从命令行运行"gradle compileJava“可以正常工作。

元数据/..log中没有错误

如果删除.metadata并重新构建/重新导入问题,则返回问题。

对于同一产品的不同开发分支,在同一系统上设置类似的设置可以正常工作。

我已经从上周的备份中恢复了开发树,那时它运行得很好。问题一出现,我就会在eclipse中对->同步进行分级。

我从每个项目(包括父项目)中删除了.metadata和所有.project .classpath .settings,并通过Gradle >项目导入

编辑20221121

在运行Eclipse2021-12之前,我从每个项目(包括父项目)中删除了所有.metadata .project .classpath .settings,并通过Gradle >项目导入。

编辑20221122

创建一个全新的工作区dir,导入git,然后运行Eclipse并执行Import > Gradle现有项目。同样的问题。

我从VM重新启动前一周恢复了保存损坏工作区的VM。Eclipse在损坏的工作区上可以很好地触发。然而,在我运行Gradle > Refresh项目之后,它就以同样的方式崩溃了。

我安装了Eclipse2022-06 (4.20)并删除了我的.metadata .settings .classpath .project文件。在Gradle导入现有项目之后,问题马上就会出现。

调查结果

在eclipse中,如果我展开公共->项目和外部依赖项,则"MangoCommon“条目是灰色的,但是”MangoCommon“项是正常的。

我的实际产品还有许多其他的子项目,其中大部分类似于“公共”,并且在从MangoCommon导入类时会出现错误。

CmbProject build.gradle

代码语言:javascript
复制
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 settings.gradle

代码语言:javascript
复制
include 'CodeGen'
include 'MangoCommon'
include 'Model'
include 'Common'

普通build.gradle

代码语言:javascript
复制
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 ....

build.gradle模型

代码语言:javascript
复制
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 ...

MangoCommon build.gradle

代码语言:javascript
复制
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同步创建的公共/. ->路径:

代码语言:javascript
复制
<?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>

环境

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-22 04:52:20

发现问题了!

级7.5.x + Buildship 3.1.6似乎被破坏了。当我将Eclipse (Preferences > Gradle >特定版本)配置为使用7.4.2时,一切都再次正常工作。

我通常将Eclipse Gradle配置为使用gradle包装器。一个月前,我从命令行将gradle包装器从7.4.2升级到了7.5.1。Gradle从命令行运行得很好,但是一旦我的dev系统重新启动,我就运行Gradle > Refresh项目,它在eclipse中第一次使用了7.5.1。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74484463

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档