【问题标题】:Grails & gradle : plugin managementGrails & gradle:插件管理
【发布时间】:2013-06-07 07:09:46
【问题描述】:

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

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

这是我的 build.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

Wich 将以下行添加到 application.properties 文件中:

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

将此行添加到我的 build.gradle 的依赖项范围中会在 gradle build 期间给我一个错误:

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 gradle grails-plugin


    【解决方案1】:

    与大多数 grails 插件一样,它们大多已过时且已死。你需要从插件中得到什么?该插件已 6 年未更新。

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

    http://grails.org/doc/latest/guide/webServices.html#REST

    在它的正下方有一个 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
          }
         }
    }
    

    【讨论】:

    • 因为我曾经用这个插件写过我的代码。如果基本的 grails 构建可以找到它,它必须有 graddle 的方法。我也可以重写我的代码
    【解决方案2】:

    最新的 Grails 使用 BuildConfig.groovy,而不是 application.propertiesbuild.gradle 仅适用于 Gradle,我认为它不能帮助您解决 Grails 依赖项。

    所以,你必须编辑你的conf/BuildConfig.groovy,放入plugins 部分:

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

    插件依赖项参见文档:http://grails.org/doc/latest/guide/conf.html#pluginDependencies

    【讨论】:

    • 这曾经在我的 BuildConfig.groovy 文件中,但我使用的是不关心这个文件的 gradle
    • 如果不使用 gradle 运行它会得到什么?只是grails run-app?
    • 并确保您使用的是compile ":rest:0.7",而不是compile 'repo.grails.org:grails-plugins-rest:0.7'
    • 行 compile 'repo.grails.org:grails-plugins-rest:0.7' 是对我的 gradle.build 的测试。如果我使用 'grails run-app' cmd 运行我的应用程序,我没有任何问题。如果我使用 'gradle grails-run-app' cmd 运行我的应用程序,我的服务器正在运行,但我在运行时收到错误,因为未解析其余插件
    • 无论如何,Gradle 说无法加载插件。 repo.grails.org:grails-plugins-rest:0.7 看起来像是 Gradle 的无效工件名称。也许是org.grails.plugins:rest:0.7?并确保您在build.gradle中配置了http://repo.grails.org/grails/plugins-releases
    【解决方案3】:

    你的英语并没有你想象的那么差。 :)

    我同意@Nix 关于插件的可用性。 相反,您可以使用相当冗长的rest-client-builder 插件。

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

    谢谢..

    【讨论】:

    • 正如我所说,使用“grails run-app”cmd 运行我的应用程序没有任何问题。当我使用 'gradle grails-run-app' cmd 时,我执行了运行时错误。我同意插件的可用性,我想我会重写我的代码,但我很乐意为将来的插件配置解决这个问题
    【解决方案4】:

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

    这是我的 build.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'
    }
    ...
    

    这是我的 build.config :

    ...
        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
    

    【讨论】:

    • 一旦在BuildConfig.groovy 中有条目,您可能需要从 build.gradle 中删除 rest 条目。
    猜你喜欢
    • 1970-01-01
    • 2012-03-06
    • 2010-10-10
    • 2017-09-21
    • 1970-01-01
    • 2014-03-22
    • 1970-01-01
    • 2017-11-15
    • 2016-09-10
    相关资源
    最近更新 更多