Gradle Script To call a REST Web service without any 3rd party plugins, any pointers?

gradle, groovy, rest

Solution

The easiest way to call REST from groovy without external libraries is executing CURL. Here's an example of calling Artifactory, getting JSON back and parsing it:

import groovy.json.JsonSlurper

task hello {
    def p = ['curl', '-u', '"admin:password"', "\"http://localhost:8081/api/storage/libs-release-local?list&deep=1\""].execute()
    def json = new JsonSlurper().parseText(p.text)
}

Problem

Hi I need to call a REST service as part of the buildscript (Gradle) without any 3rd party plugins, how could I use Groovy to do that? (My first attempt) ``` repositories { mavenCentral() } dependencies { complie "org.codehaus.groovy.modules.http-builder:http-builder:0.5.2" } task hello { def http = new HTTPBuilder("http://myserver.com:8983/solr/select?q=*&wt=json") http.auth.basic 'username', 'password' http.request(GET, JSON ) { req -> } } ```

Original source