Gradle 在构建 Grails 项目时给出 ClassNotFoundException

Posted

技术标签:

【中文标题】Gradle 在构建 Grails 项目时给出 ClassNotFoundException【英文标题】:Gradle giving ClassNotFoundException while building Grails project 【发布时间】:2015-07-04 01:33:28 【问题描述】:

我正在尝试使用 gradle-grails-plugin 来构建现有的(小型)Grails 项目。这应该工作吗? build.gradle中的依赖和buildConfig.groovy中指定的依赖是什么关系?

无论如何,我有两个项目,所以最上面的build.gradle 文件在父目录中,看起来像:

buildscript 
   repositories 
      jcenter()
   
   dependencies 
      classpath "org.grails:grails-gradle-plugin:2.2.0.RC1"
   


task wrapper(type: Wrapper) 
   gradleVersion = '2.3'

然后Grails项目中的build.gradle如下:

apply plugin: "grails"

repositories 
   grails.central() //creates a maven repo for the Grails Central repository (Core libraries and plugins)


grails 
   grailsVersion = '2.4.4'
   groovyVersion = '2.3.9'
   springLoadedVersion '1.2.0.RELEASE'


dependencies 
   bootstrap "org.grails.plugins:tomcat:7.0.55.3" 
   compile 'org.grails.plugins:asset-pipeline:3.0.1' 

   compile 'org.grails.plugins:scaffolding:2.1.2'
   compile 'org.grails.plugins:cache:1.1.8'

   runtime 'org.grails.plugins:hibernate4:4.3.1.1'
   runtime 'org.grails.plugins:database-migration:1.3.8'
   runtime 'org.grails.plugins:jquery:1.11.0'

但是,当我运行 ./gradlew war 时,我会返回:

Caused by: java.long.ClassNotFoundException: grails.artefact.Service

任何人都可以对此有所了解吗?几乎没有通过谷歌引用它,它似乎是一个 Grails 3.x 类?另外,我使用的是 Java 1.7。

【问题讨论】:

【参考方案1】:

grails.artefact.Service 确实可以从 grails 框架 v3.0 访问 - 正如 here 所见。

使用下面的语句grailsVersion = '2.4.4' v2.4.4 被指定使用,看起来一切正常。破坏构建的是以下dependencies 条目:

compile 'org.grails.plugins:asset-pipeline:3.0.1' 

在这个包中有一个类asset/pipeline/grails/AssetProcessorService,它导入了在运行时没有加载的grails.artefact.Service(可能是因为使用了v2.4.4)。

不幸的是,除了排除这种依赖关系之外,我无法提出任何解决方案。我不是 grails 开发人员,也没有设置环境。

希望能有所帮助。

【讨论】:

@JoeG,有帮助吗?

以上是关于Gradle 在构建 Grails 项目时给出 ClassNotFoundException的主要内容,如果未能解决你的问题,请参考以下文章

GRAILS ---命令 grails war 和 gradle build 有啥区别?

Grails 包绕过证书

Grails & gradle:插件管理

如何在 Grails 3 Gradle 项目中控制 H2 驱动程序版本?

如何告诉 Grails 使用 Gradle 解决依赖关系

使用 Gradle 运行时设置 Grails 端口