Snite
Snite

Reputation: 169

Grails & gradle : plugin management

Firstly, sorry for my poor English, I'm french, hope my question will be clear.

I'm building a grails project with gradle, and want to use the rest plugin.

Here is my build.gradle conf file :

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}"
    }
}

Here is the rest plugin : http://grails.org/plugin/rest

Previously, get this plugin was quite simple :

grails install-plugin rest

Wich adding the following line into application.properties file :

plugins.rest=0.7

I just don't know how to add this plugin into my buildFile.

My grails application could be run, but I get an error at runtime :

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

Adding this line into the dependencies scope of my build.gradle give me an error during gradle build :

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

error :

* 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

I understand that last error clearly.

So here is my question : How add rest plugin for grails usin gradle built ?

Upvotes: 1

Views: 5172

Answers (4)

Snite
Snite

Reputation: 169

Ok, igor solve my problem (but I get another) :

Here is my 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'
}
...

Here is my build.config :

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

The new error whith this line (after downloading sources) is :

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

Upvotes: 0

dmahapatro
dmahapatro

Reputation: 50275

Your English is not at all bad as you thought it would be. :)

I agree with @Nix on the the usability of the plugin. Instead, you can use rest-client-builder plugin which is pretty verbose.

Again you have to follow the way @Igor Artamonov has mentioned in his answer for the setup.

Merci..

Upvotes: 0

Igor Artamonov
Igor Artamonov

Reputation: 35951

Latest Grails uses BuildConfig.groovy for dependencies, not application.properties. build.gradle is for Gradle only, I don't think it can help you with Grails dependencies.

So, you have to edit your conf/BuildConfig.groovy, put into plugins sections a:

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

See docs for plugins dependencies: http://grails.org/doc/latest/guide/conf.html#pluginDependencies

Upvotes: 2

Nix
Nix

Reputation: 58602

As with most grails plugins they are mostly outdated, and dead. What do you need from the plugin ? That plugin hasn't been updated in 6 years.

Almost all things you need to be done for REST are built in. Serializing, URL Routing, etc.

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

Right under it there is a webservices section, that shows you how to perform a HTTP request, and then get the JSON response:

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

Upvotes: 2

Related Questions