HTTP Builder Problem

Hallo,

we use http builder, but with some problems:

First Problem: I have following gralde build script:

buildscript {
repositories {
maven {
credentials {
username repoUsername
password repoPassword
}
url 'http://our-url'
}
      // Add here your classpath libs / build dependencies
      dependencies {
              classpath "org.codehaus.groovy.modules.http-builder:http-builder:0.5.2"
      }
  }
    }

When I try to run a task, where the http Builder class is used, I get following error:

startup failed: [exec] Script1.groovy: 1: unable to resolve class groovyx.net.http.HTTPBuilder [exec] @ line 1, column 1. [exec] new groovyx.net.http.HTTPBuilder( “http://${x}:${y}”) [exec] ^ [exec] 1 error

What do I do false?

Second Problem: So I have tried to do add the build dependecy so on that kind: configurations{ buildDependencies } dependencies {

buildDependencies( ‘org.codehaus.groovy.modules.http-builder:http-builder:0.5.2’ ) { exclude group:‘org.codehaus.groovy’, module:‘groovy’ }

}

// following line add libs to script classpath

configurations.buildDependencies.each {File file -> GroovyObject.class.classLoader.addURL(file.toURL());}

As you see, I add the build dependency to the class path. The most time I run that tasks of this scripts, it is no problem. But sometimes, when I set up a new project and many libs must be downloaded I get an error. Then, when I comment out the line

"buildDependencies( 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.2' ) { exclude group:'org.codehaus.groovy', module:'groovy' }"

I have no problem, it works. Then after the dependencies are downloaded, I can make the builddependency line active.

So how is it possible to use the “org.codehaus.groovy.modules.http-builder:http-builder:0.5.2” ?? Without getting errors? I thank you very much for answering and help me fixing that problem!

It should be possible to use 'classpath “org.codehaus.groovy.modules.http-builder:http-builder:0.5.2” ’ in my dependency, but it is not possible. So what is the wayx to use that dependency without getting errors?

Thanks very much for you help!

ad 1. Works fine for me. Make sure to try with Gradle 1.0.

ad 2. I don’t see why this hack would be required, and I wouldn’t be too surprised if it sometimes caused problems.

PS: Please pay more attention to formatting your posts (correct indentation, etc.).

Hallo Peter,

thank you very much for your reply! I appreciate it very much to get your help. I hope you can help me. I paste now all the code that I use, but it does not work. I also work with gradle 1.0!

buildscript {
 repositories {
  maven {
   credentials {
    username repoUsername
    password repoPassword
   }
   url 'http://our-url'
  }
  // Add here your classpath libs / build dependencies
  dependencies { classpath "org.codehaus.groovy.modules.http-builder:http-builder:0.5.2" }
 }
}
      task refreshWebscripts << {
    refreshWebscripts()
}
  void refreshWebscripts()
{
 def host = "localhost"
 def port = "8080"
 def user = "admin"
 def pass = "admin"
   def http = Eval.xy(host, port, 'new groovyx.net.http.HTTPBuilder( "http://${x}:${y}")' )
 http.auth.basic user, pass
}

If you try to start the “refreshWebscripts” task, you get following exception: * What went wrong:

[exec] Execution failed for task ‘:refreshWebscripts’.

[exec] > startup failed:

[exec]

Script1.groovy: 1: unable to resolve class groovyx.net.http.HTTPBuilder

[exec] @ line 1, column 1.

[exec]

new groovyx.net.http.HTTPBuilder( “http://${x}:${y}”)

[exec]

^

[exec]

[exec]

1 error

Please tell me if you have the same problem! Thank you very much for your help!

God Bless You!

Shalom Amin

That is why I / we do it on that kind:

repositories {
 maven {
  credentials {
   username repoUsername
   password repoPassword
  }
  url 'http:/our-url'
 }
        configurations{ buildDependencies }
 dependencies {
  // Add here only libs, when your libs are not
      buildDependencies( 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.2' ) { exclude group:'org.codehaus.groovy', module:'groovy' }
    }
 // add libs to script classpath
 configurations.buildDependencies.each {File file -> GroovyObject.class.classLoader.addURL(file.toURL());}
}

If we now start the first task in the last post, no error appears. BUT: Sometimes other errors appear! We do not know how to make use of the http builder without the hack, the last code you saw. Here the sector:

configurations{ buildDependencies }
 dependencies {
  // Add here only libs, when your libs are not
      buildDependencies( 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.2' ) { exclude group:'org.codehaus.groovy', module:'groovy' }
    }
 // add libs to script classpath
 configurations.buildDependencies.each {File file -> GroovyObject.class.classLoader.addURL(file.toURL());}

I thank you very much when you help me.

Shalom Amin Zamani

Why use ‘Eval’? The problem is that ‘Eval’ is using the wrong class loader (that of Groovy).

Hi Peter,

thanks for you answer/reply! Can you tell me how we could change the it? Without using of Eval?

Thank you very much for your help!

Shalom & Best regards Amin Zamani

def http = new groovyx.net.http.HTTPBuilder("http://$host:$port")

Hey, thank you very much! Good work. Now it works. But now I have to fix the next Eval’s. Can you tell me how I have to fix the next 2 Evals ?

void refreshWebscripts()
  {
   def host = "localhost"
   def port = "8080"
   def user = "admin"
   def pass = "admin"
             //def http = Eval.xy(host, port, 'new groovyx.net.http.HTTPBuilder( "http://${x}:${y}")' )^
   def http = new groovyx.net.http.HTTPBuilder("http://$host:$port");
   http.auth.basic user, pass
      // perform a GET request, expecting TEXT response data
   def get = Eval.me('groovyx.net.http.Method.GET')
   //def get = new groovyx.net.http.Method.GET
   def text = Eval.me('groovyx.net.http.ContentType.TEXT')
   //def text = new groovyx.net.http.ContentType.TEXT
     }

The Line that I have commented “def text = new groovyx.net.http.ContentType.TEXT”, have I fixed it right?

I ask, because I tried to do the same within the last commented line “def text = new groovyx.net.http.ContentType.TEXT”, but it does not work. Then I get following error:


Could not compile build file ‘C:\Users\westernacher\workspace-test\alfresco-project-template\build.gradle’.

[exec] > startup failed:

[exec]

build file ‘C:\Users\westernacher\workspace-test\alfresco-project-template\build.gradle’: 1179: expecting ‘(’, found ‘def’ @ line 1179, column 4.

[exec]

def text = new groovyx.net.http.ContentType.TEXT

[exec] BUILD FAILED

[exec] Total time: 3.036 secs

[exec]

^

[exec]

[exec]

1 error -----------------

Do you know how I have to replace both eval Statements inside my code?

However, I thank you very much for you valuable help!

Best regards

& Shalom Amin Zamani

All I need to know is how to fix the following eval statements from the http builder dependecy? :

// perform a GET request, expecting TEXT response data
            def get = Eval.me('groovyx.net.http.Method.GET')
            def text = Eval.me('groovyx.net.http.ContentType.TEXT')

When I try do / fix it the as following kind:

def get = new groovyx.net.http.Method.GET
def text = new groovyx.net.http.ContentType.TEXT

then I get the above last exception I wrote. So how can I use these classes without eval statement?

Thanks very much for your reply!

Shalom Amin Zamani

I my fault… I guess I have it…

I have to write :

def get = groovyx.net.http.Method.GET
def text = groovyx.net.http.ContentType.TEXT

without “new” -:wink: My mistake… It works!! Great work!! Thank you for you help! You are great that you have shown me the right way!!

God Bless You!!

Shalom Amin Zamani

Hallo,

now I have an other problem. Infact I want to put the code inside my gradle plugin class. This class now is not able to resovle the classes. I have created therefor a new ticket. I hope that is ok:

http://forums.gradle.org/gradle/topics/unable_to_resolve_class_groovyx_net_http_httpbuilder?rfm=1

Thanks very much for your help!

Shalom Amin