@Grab无法在intellij IDE中使用groovy

时间:2017-09-24 18:07:25

标签: grails intellij-idea groovy grape groovy-console

我是groovy的新手,ans正在练习使用http-builder包进行REST调用,我试图使用@Grab注释添加依赖项,但它不下载依赖项,注释是不工作,

我的代码:

import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )

def restClient = RESTClient('http://api.icmdb.com')
restClient.contentType = ContentType.JSON
restClient.get(path:'/jokes/random'){response,json->
    println response.status
    println json
}

我得到的例外:

 Caught: groovy.lang.MissingMethodException: No signature of method: com.groovy.practice.RESTCall.RESTClient() is applicable for argument types: (String) values: [http://api.icmdb.com]
groovy.lang.MissingMethodException: No signature of method: com.groovy.practice.RESTCall.RESTClient() is applicable for argument types: (String) values: [http://api.icmdb.com]

所以基本上它没有下载http-builder,因此它找不到RESTClient类型的签名。

我的常规版本是:2.6.0-alpha-1 Intellij版本:2017.2.3

有什么可以在groovy或intellij IDE中启动Grape,任何人都可以请求帮助,我被困在这里。

2 个答案:

答案 0 :(得分:3)

尝试将插入符号放在Grapes依赖关系&按Alt + Enter然后抓取依赖项。

答案 1 :(得分:0)

我的第一个想法是放弃IDE的问题。请尝试使用groovy解释器在IDE外部执行Groovy程序。如果问题再次出现,我会检查我的〜/ .groovy / grapeConfig.xml。

是否有任何连接问题或公司代理会阻止您直接访问maven中央互联网站点?在这种情况下,您是否应该尝试在Groovy调用中配置代理选项?或者,如果您处于合作环境中,是否存在任何类型的公司存储库,例如Artifactory或Nexus,您可以尝试使用它们来规避您的问题?

相关问题