【问题标题】:*unable to resolve class" issue when upgrading from grails 2.5.4 to grails 3.3.11*从 grails 2.5.4 升级到 grails 3.3.11 时出现“无法解决类”问题
【发布时间】:2020-09-14 15:08:39
【问题描述】:

我继承了一个基于 Grails 2.5.4 的多模块 grails 应用程序。

运行良好,但我需要升级到 3.x。

我安装了groovy 3.0.4和grails 3.3.11,根据官网(https://docs.grails.org/3.0.x/guide/upgrading.html)提供的教程完成了grails升级任务。

当我尝试构建项目时,我面临多个与基类相关的“无法解决类”问题,例如:

Starting a Gradle Daemon (subsequent builds will be faster)
:compileAstJava NO-SOURCE
:compileAstGroovy NO-SOURCE
:processAstResources NO-SOURCE
:astClasses UP-TO-DATE
:compileJava NO-SOURCE
:configScript
:compileGroovy
startup failed:
C:\repo\upgraded-app\myapp-core\grails-app\domain\bittt\holders\Exclusion.groovy: 5: unable to     resolve class org.grails.databinding.BindingFormat
 @ line 5, column 1.
   import org.grails.databinding.BindingFormat
   ^

C:\repo\upgraded-app\myapp-core\grails-app\domain\bittt\migration\CustomsLgcy.groovy: 5: unable to resolve class org.postgresql.core.Query
 @ line 5, column 1.
   import org.postgresql.core.Query
   ^

C:\repo\upgraded-app\myapp-core\grails-app\services\bittt\ExclusionService.groovy: 13: unable to resolve class org.grails.web.servlet.mvc.GrailsParameterMap
 @ line 13, column 1.
   import org.grails.web.servlet.mvc.GrailsParameterMap
   ^

C:\repo\upgraded-app\myapp-core\grails-app\services\bittt\NotificationService.groovy: 12: unable to resolve class org.grails.commons.GrailsApplication
 @ line 12, column 1.
   import org.grails.commons.GrailsApplication
   ^
...

我的 myapp.core build.gradle 文件包含以下内容:

buildscript {
    repositories {
        mavenLocal()
        maven { url "https://repo.grails.org/grails/core" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.15.1"
    }
}

version "0.1"
group "myapp.core"

apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-plugin"
apply plugin:"org.grails.grails-plugin-publish"
apply plugin:"asset-pipeline"
apply plugin:"org.grails.grails-gsp"

repositories {
    mavenLocal()
    maven { url "https://repo.grails.org/grails/core" }
}

dependencies {
    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.grails:grails-core"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-starter-tomcat"
    compile "org.grails:grails-web-boot"
    compile "org.grails:grails-logging"
    compile "org.grails:grails-plugin-rest"
    compile "org.grails:grails-plugin-databinding"
    compile "org.grails:grails-plugin-i18n"
    compile "org.grails:grails-plugin-services"
    compile "org.grails:grails-plugin-url-mappings"
    compile "org.grails:grails-plugin-interceptors"
    compile "org.grails.plugins:cache"
    compile "org.grails.plugins:async"
    compile "org.grails.plugins:scaffolding"
    compile "org.grails.plugins:events"
    compile "org.grails.plugins:hibernate5"
    compile "org.hibernate:hibernate-core:5.1.16.Final"
    compile "org.grails.plugins:gsp"

    compile 'org.grails.plugins:spring-security-core:3.2.3'
    compile 'org.grails.plugins:spring-security-acl:3.2.1'
    compile "org.grails.plugins:phonenumbers:0.10"

    console "org.grails:grails-console"
    profile "org.grails.profiles:web-plugin"
    provided "org.grails:grails-plugin-services"
    provided "org.grails:grails-plugin-domain-class"
    
    runtime "org.glassfish.web:el-impl:2.1.2-b03"
    runtime "com.h2database:h2"
    runtime "org.apache.tomcat:tomcat-jdbc"
    runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.15.1"
    testCompile "org.grails:grails-gorm-testing-support"
    testCompile "org.grails.plugins:geb"
    testCompile "org.grails:grails-web-testing-support"
    testCompile "org.grails.plugins:geb:1.1.2"
    testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
    testRuntime "org.seleniumhq.selenium:selenium-chrome-driver:2.47.1"
}

bootRun {
    jvmArgs('-Dspring.output.ansi.enabled=always')
    addResources = true
    String springProfilesActive = 'spring.profiles.active'
    systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}

tasks.withType(Test) {
    systemProperty "geb.env", System.getProperty('geb.env')
    systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
    systemProperty "webdriver.chrome.driver", System.getProperty('webdriver.chrome.driver')
    systemProperty "webdriver.gecko.driver", System.getProperty('webdriver.gecko.driver')
}

assets {
    minifyJs = true
    minifyCss = true
}

我真的不明白为什么我会收到这些错误,因为相关的依赖项似乎已经到位......我在这里遗漏了什么?

谢谢:)

【问题讨论】:

    标签: grails groovy


    【解决方案1】:

    C:\repo\upgraded-app\myapp-core\grails-app\domain\bittt\holders\Exclusion.groovy: 5:无法解析类org.grails.databinding.BindingFormat@ 第 5 行,第 1 列。导入 org.grails.databinding.BindingFormat

    在 Grails 3.3.11 中,包是 grails.databinding,而不是 org.grails.databinding (https://github.com/grails/grails-core/blob/v3.3.11/grails-databinding/src/main/groovy/grails/databinding/BindingFormat.java)。 org.grails.web.servlet.mvc.GrailsParameterMap (https://github.com/grails/grails-core/blob/v3.3.11/grails-web-common/src/main/groovy/grails/web/servlet/mvc/GrailsParameterMap.java) 和 import org.grails.commons.GrailsApplication (https://github.com/grails/grails-core/blob/v3.3.11/grails-core/src/main/groovy/grails/core/GrailsApplication.java) 的包名称也发生了变化。

    org.postgresql.core.Query 是一个单独的问题。看起来您的项目没有表达对 postgres 库的依赖关系,因此该类对应用程序不可用。

    【讨论】:

    • 非常感谢,它确实对第一部分有所帮助。关于 GrailsParameterMap 类,虽然我不确定是否理解您的建议,但导入行已经是“import org.grails.web.servlet.mvc.GrailsParameterMap”,但我得到(相同)以下错误:C:\repo\ upgrade-app\myapp-core\grails-app\services\bittt\ExclusionService.groovy: 13: 无法解析类 org.grails.web.servlet.mvc.GrailsParameterMap @ 第 13 行,第 1 列。导入 org.grails.web .servlet.mvc.GrailsParameterMap 我在这里遗漏了什么吗?
    • 使用import grails.web.servlet.mvc.GrailsParameterMap。答案中的一个链接指向该类。
    猜你喜欢
    • 1970-01-01
    • 2015-09-10
    • 1970-01-01
    • 2015-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-28
    相关资源
    最近更新 更多