如果说明中未提及,导入Grails插件的正确方法是什么



在确认插件安装正确后,我试图使用这个Grails插件中定义的方法:

https://github.com/agorapulse/grails-open-exchange-rates/blob/master/grails-app/services/grails/plugin/openexchangerates/OpenExchangeRatesService.groovy

对于所有我可以推测的,我在我的控制器中添加以下导入行:

import grails.plugin.openexchangerates

但是编译器一直唠叨它无法解析这个类。我尝试了以下所有组合,但都无济于事:

grails.plugin.openexchangerates.*
services.grails.plugin.openexchangerates
services.grails.plugin.openexchangerates.*

等。

我在这里遗漏了什么明显的东西?

顺便说一下,它并没有导入Grails插件。只是标准的(groovy/java/jvm)导入,但对于来自grails插件的类来说,这是很常见的情况。

这个类有package grails.plugin.openexchangerates,所以你可以这样做:

import grails.plugin.openexchangerates.*

import grails.plugin.openexchangerates.OpenExchangeRatesService

但要确保插件被添加到依赖项,到BuildConfig,作为

compile ':open-exchange-rates:0.1'

Plugin readme建议使用runtime ':open-exchange-rates:0.1',但在这种情况下,编译器在类路径中没有插件类。您需要使用compile作用域。有关依赖范围的更多信息:http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

最新更新