Grails & gradle:插件管理



首先,抱歉我的英语不好,我是法国人,希望我的问题能说清楚。

我正在用gradle构建一个grails项目,并且想使用rest插件。

这是我的构建。Gradle配置文件:

import org.grails.gradle.plugin.GrailsTask
version = '1.0'
grailsVersion = '2.2.1'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'grails'

buildscript {
        repositories {
            mavenCentral()
            mavenRepo name: "grails", url: 'http://repo.grails.org/grails/repo'
        }
        dependencies {
            classpath "org.grails:grails-gradle-plugin:1.1.1-SNAPSHOT"
        }
}
repositories {
    mavenCentral()
    mavenRepo name: 'grails', url: 'http://repo.grails.org/grails/repo'
    mavenRepo name: 'nexus', url: 'http://nexusurl.fr'
    mavenRepo url: 'http://repo.grails.org/grails/plugins'
}
uploadArchives {
    repositories {
       mavenDeployer {
             repository(url: 'http://url') {
             authentication(userName: 'log', password: 'pass')
}
             pom.version = '0.0.0'
             pom.artifactId = 'yo'
             pom.groupId = 'com.something'
             pom.packaging = 'war'
       }
    }
}

dependencies {
    ['dependencies', 'resources', 'core',  'plugin-domain-class', 'plugin-tomcat', 'plugin-services'].each { plugin ->
        compile "org.grails:grails-$plugin:2.2.1"
    }
    compile 'repo.grails.org:grails-plugins-rest:0.7'
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.9'
    compile 'org.codehaus.jackson:jackson-core-asl:1.9.9'
    compile 'com.googlecode.json-simple:json-simple:1.1'
    bootstrap 'org.codehaus.groovy:groovy-all:1.8.6'
}
GRAILS_TASK_PREFIX = 'grails-'
if (name.startsWith(GRAILS_TASK_PREFIX)) {
    project.task(name, type: GrailsTask) {
        command "${name - GRAILS_TASK_PREFIX}"
    }
}

下面是剩下的插件:http://grails.org/plugin/rest

以前,获取这个插件很简单:

grails install-plugin rest

将以下行添加到应用程序中。属性文件:

plugins.rest=0.7

我只是不知道如何添加这个插件到我的buildFile.

我的grails应用程序可以运行,但是我在运行时得到一个错误:

Error |
2013-06-11 14:20:41,916 [http-bio-8080-exec-8] ERROR errors.GrailsExceptionResolver  - MissingMethodException occurred when processing request: [POST] /dwgui/signIn/login - parameters:
username: demo-user
password: ***
No signature of method: com.ftprod.dwgui.security.AuthenticationService.withHttp() is applicable for argument types: (java.util.LinkedHashMap, com.ftprod.dwgui.security.AuthenticationService$_testSign
In_closure1) values: [[uri:http://data.iraiser.eu], com.ftprod.dwgui.security.AuthenticationService$_testSignIn_closure1@2786aa0f]. Stacktrace follows:
Message: No signature of method: com.ftprod.dwgui.security.AuthenticationService.withHttp() is applicable for argument types: (java.util.LinkedHashMap, com.ftprod.dwgui.security.AuthenticationService$
_testSignIn_closure1) values: [[uri:http://data.iraiser.eu], com.ftprod.dwgui.security.AuthenticationService$_testSignIn_closure1@2786aa0f]
    Line | Method
->>   28 | testSignIn in com.ftprod.dwgui.security.AuthenticationService
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|     14 | login      in com.ftprod.dwgui.security.SignInController
|   1145 | runWorker  in java.util.concurrent.ThreadPoolExecutor
|    615 | run        in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . .  in java.lang.Thread

将这行添加到构建的依赖范围中。Gradle给我一个错误在Gradle构建:

compile 'repo.grails.org:grails-plugins-rest:0.7'
错误:

* What went wrong:
Execution failed for task ':grails-run-app'.
> Could not find repo.grails.org:grails-plugins-rest:0.7.
  Required by:
      :dwgui:1.0

我很清楚最后一个错误。

所以这是我的问题:如何使用gradle构建为grails添加rest插件

最新的Grails使用BuildConfig.groovy作为依赖项,而不是application.propertiesbuild.gradle只是为Gradle准备的,我不认为它能帮助你解决Grails的依赖。

所以,你必须编辑你的conf/BuildConfig.groovy,放入plugins章节a:

plugins {
   ...    
   compile ":rest:0.7"
}

查看插件依赖文档:http://grails.org/doc/latest/guide/conf.html#pluginDependencies

与大多数grails插件一样,它们大多是过时的,并且已经死亡。你需要从插件中得到什么?这个插件已经6年没有更新了。

几乎所有需要为REST做的事情都是内置的。序列化、URL路由等

http://grails.org/doc/latest/guide/webServices.html休息

下面有一个webservices部分,向您展示如何执行HTTP请求,然后获得JSON响应:

import groovyx.net.http.*
import static groovyx.net.http.ContentType.JSON
def http = new HTTPBuilder("http://localhost:8080/amazon")
http.request(Method.GET, JSON) {
    url.path = '/book/list'
    response.success = { resp, json ->
      for (book in json.books) {
        println book.title
      }
     }
}

你的英语一点也不像你想象的那么差。:)

我同意@Nix对插件可用性的看法。相反,你可以使用rest-client-builder插件,它非常冗长。

你必须再次遵循@Igor Artamonov在他的回答中提到的设置方法。

谢谢. .

好吧,我解决了我的问题(但我得到了另一个):

这是我的构建。gradle:

...
repositories {
    mavenCentral()
    mavenRepo name: 'grails', url: 'http://repo.grails.org/grails/repo'
    mavenRepo name: 'nexus', url: 'http://integration.ftprod.fr/nexus/content/groups/public/'
    mavenRepo url: 'http://repo.grails.org/grails/plugins'
    mavenRepo url: 'http://repo.grails.org/grails/plugins-releases'
}
...
dependencies {
    ['dependencies', 'resources', 'core',  'plugin-domain-class', 'plugin-tomcat', 'plugin-services'].each { plugin ->
        compile "org.grails:grails-$plugin:2.2.1"
    }
    compile 'org.grails.plugins:rest:0.7'
    compile 'com.ftprod.dw:dw-client-api:0.0.28'
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.9'
    compile 'org.codehaus.jackson:jackson-core-asl:1.9.9'
    compile 'com.googlecode.json-simple:json-simple:1.1'
    bootstrap 'org.codehaus.groovy:groovy-all:1.8.6'
}
...

这是我的构建。配置:

...
    plugins {
        ...
    compile ":rest:0.7"
    }
...

这行(下载源代码后)的新错误是:

compile 'org.grails.plugins:rest:0.7'
* What went wrong:
Execution failed for task ':grails-refresh-dependencies'.
> loader constraint violation: when resolving overridden method "org.apache.tools.ant.helper.ProjectHelper2$RootHandler.setDocumentLocator(Lorg/xml/sax/Locator;)V" the class loader (instance of org/gr
ails/launcher/RootLoader) of the current class, org/apache/tools/ant/helper/ProjectHelper2$RootHandler, and its superclass loader (instance of <bootloader>), have different Class objects for the type
andler.setDocumentLocator(Lorg/xml/sax/Locator;)V used in the signature

最新更新