如果没有在说明中提到,导入Grails插件的正确方法是什么

时间:2014-07-21 15:50:04

标签: grails plugins

我确认在确认插件安装正确后尝试使用此Grails插件中定义的方法:

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

对于我可以推测的所有内容,我在我的Controller中添加以下导入行:

import grails.plugin.openexchangerates

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

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

我在这里错过了什么明显的事情?

1 个答案:

答案 0 :(得分:1)

它没有导入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'

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