Unable to resolve class groovyx.net.http.HTTPBuilder


(amin.zamani) #1

Hallo,

I want to use the http builder classes inside my gralde plugin class. But how can I do that?

I have in my gradle Plugin class following code:

def http = new groovyx.net.http.HTTPBuilder("http://$host:$port");
def get = groovyx.net.http.Method.GET
def text = groovyx.net.http.ContentType.TEXT

I have downloaded the http-builder-0.5.2.jar from here “http://groovy.codehaus.org/modules/http-builder/download.html” and set it into the classpath of my eclipse project, insdie the .classpath file:

<classpathentry kind="lib" path="D:/Software/gradle/http-builder-0.5.2.jar"/>

When I try to build my plugin, I get following exception: startup failed:

C:\Users\westernacher\workspace-test\AlfrescoPlugin\src\main\groovy\org\gradle\AlfrescoPlugin.groovy: 975: unable to resolve class groovyx.net.http.HTTPBuilder

@ line 975, column 15.

def http = new groovyx.net.http.HTTPBuilder(“http://$host:$port”);

^

1 error

Where is the problem? Thank you very much for your help!

Best regards & Shalom Amin Zamani


(amin.zamani) #2

The next stept that I tried was to delete inside the eclipse .classpath the following line:

<classpathentry kind="lib" path="D:/Software/gradle/http-builder-0.5.2.jar"/>

The right way is to set the classpathc dependencies inside the buildscript (gradle), so I have done the following inside the buildscript from my plugin:

buildscript {
 repositories {
    maven {
   credentials {
    username artifactoryRepoUsername
    password artifactoryRepoPassword
   }
   url 'http://xyz'
  }
    maven {
   credentials {
    username artifactoryRepoUsername
    password artifactoryRepoPassword
   }
   url 'http://xyz'
  }
 }
   dependencies { classpath "org.codehaus.groovy.modules.http-builder:http-builder:0.5.2" }
}

But I still get the following exception:

startup failed:
C:\Users\westernacher\workspace-test\AlfrescoPlugin\src\main\groovy\org\gradle\AlfrescoPlugin.groovy: 976: unable to resolve class groovyx.net.http.HTTPBuilder
  @ line 976, column 15.
      def http = new groovyx.net.http.HTTPBuilder("http://$host:$port");
                 ^
  1 error

(amin.zamani) #3

Thank you very much when someone can help!

Best regards & Shalom

Amin Zamani


(amin.zamani) #4

Does someone know how I could use

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

without getting exceptions? That is my only question, then I am finish with my questions.

Shalom Amin Zamani


(amin.zamani) #5

This is all my project:

  1. Inside my Project is a groovy class which is the plugin class:
class AlfrescoPlugin implements Plugin<Project> {
   private Project project;
   AlfrescoPlugin() {
 }
   @Override
 public void apply(Project project) {
  this.project = project;
 }
   void refreshWebscripts(sub)
 {
  def host =
'localhost';
  def port =
'8080';
  def user =
'admin'
  def pass = 'admin'
    // Next line can not be resolved
  def http = new groovyx.net.http.HTTPBuilder("http://$host:$port");
  http.auth.basic user, pass
    def get = groovyx.net.http.Method.GET
  def text = groovyx.net.http.ContentType.TEXT
     }
}

And this is my gradle buildscript:

apply plugin: 'groovy'
apply plugin: 'java'
    dependencies {
 compile gradleApi()
 groovy localGroovy()
   // dependencies{ classpath "org.codehaus.groovy.modules.http-builder:http-builder:0.5.2" }
   testCompile 'junit:junit:4.8.2'
}
  apply plugin: 'maven'
  buildscript {
 repositories {
    maven {
   credentials {
    username artifactoryRepoUsername
    password artifactoryRepoPassword
   }
   url 'http://xyz'
  }
    maven {
   credentials {
    username artifactoryRepoUsername
    password artifactoryRepoPassword
   }
   url 'http:/xyz'
  }
 }
   dependencies { classpath "org.codehaus.groovy.modules.http-builder:http-builder:0.5.2" }
}
  group = 'com.westernacher.gradle.plugins'
version = '1.0.0-SNAPSHOT'
  uploadArchives {
 repositories {
  mavenDeployer {
   repository(url: 'http://xyz'){
    authentication(userName: artifactoryRepoUsername, password: artifactoryRepoPassword)
   }
  }
 }
}

Nothing more.When I start the tasks “clean build” I get following error:

:clean
:compileJava UP-TO-DATE
:compileGroovystartup failed:
C:\Users\westernacher\workspace-test\AlfrescoPlugin\src\main\groovy\org\gradle\AlfrescoPlugin.groovy: 977: unable to resolve class groovyx.net.http.HTTPBuilder
  @ line 977, column 14.
     def http = new groovyx.net.http.HTTPBuilder("http://$host:$port");
                ^
  1 error

Where is the problem? That was all to know about my plugin, that I want to create. There is nothing more. When I comment out or use Eval statement for the error line it would work. But this is not a good solution.

Please help someone me. I am developing a great alfresco plugin… For the best open source ecm of the world!

I thank you very very much for your help!

Shalom Amin Zamani


(amin.zamani) #6

I develop this plugin for our company. The next step would be to make this plugin public for everyone. But the first thing is to get it work. Thanks very much!

Shalom Amin Zamani


(amin.zamani) #7

Problem is fixed. The problem was, that I have imported inside my eclipse projekt the build dependecy 2 times.