2016-11-11 25 views
0

什么classspath用于编译/执行Grails的application.groovy?什么classspath用于执行Grails的application.groovy

在我application.groovy,我实例化一个自定义类(包含在一个依赖的JAR),并将其分配给配置的属性之一,像这样:

environments { 
    production { 
     configProperty = new com.example.CustomClass() 

我最近升级从我的Grails应用3.1.5至3.2.2,现在这不再起作用。

我收到一个错误,如下面的时候我尝试运行grails run-app

Error occurred running Grails CLI: startup failed: 
script14788250424471597489853.groovy: 43: unable to resolve class com.example.CustomClass 
@ line 43, column 33. 
     configProperty = new com.example.CustomClass() 

(请注意,该代码是在production块,但我发展(run-app)运行这让我)

所以我猜我只需要添加我的依赖项(包含CustomClass)到适当的类路径,但我不知道哪一个。

我使用gradle产出,并在我的build.gradle文件中的以下,含CustomClass依赖拉:

buildscript { 
    dependencies { 
     classpath "com.example:custom-module:1.1" 
// ... 
dependencies { 
    compile group: 'com.example', name: 'custom-module', version:'1.1' 
} 

回答

1

grails-app/conf/application.groovy文件不应引用应用程序类,因为它是之前阅读汇编。如果你想参考应用类的配置请使用grails-app/conf/runtime.groovy

+0

谢谢。这是记录在任何地方? [此搜索](https://www.google.com/search?sclient=psy-ab&btnG=Search&q=grails+runtime.groovy#q=grails+%2B%22runtime.groovy%22)没有找到任何结果。 – GreenGiant

+0

'runtime.groovy'文件看起来像'application.groovy'一样执行。参见['GroovyConfigPropertySourceLoader.load()'](https://github.com/grails/grails-core/blob/master/grails-core/src/main/groovy/org/grails/core/cfg/GroovyConfigPropertySourceLoader.groovy )。 – GreenGiant