2016-11-11 29 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