2014-10-10 38 views
0

新建Grails和嘗試使用的HttpClient從Apache來使用它集成測試...所以我把它的依賴:Grails中使用了HTTPClient 2.4

dependencies { 
    // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g. 
    // runtime 'mysql:mysql-connector-java:5.1.29' 
    // runtime 'org.postgresql:postgresql:9.3-1101-jdbc41' 
    test "org.grails:grails-datastore-test-support:1.0-grails-2.4" 
    compile 'org.apache.httpcomponents:httpcore:4.1.2' 
    compile 'org.apache.httpcomponents:httpclient:4.1.2' 
    build 'org.apache.httpcomponents:httpcore:4.1.2' 
    build 'org.apache.httpcomponents:httpclient:4.1.2' 
    test 'org.apache.httpcomponents:httpcore:4.1.2' 
    test 'org.apache.httpcomponents:httpclient:4.1.2' 
} 

在build.config,預計能使用它的測試,如

class MyControllerTests extends GroovyTestCase { 
    @Test 
    void testApacheHttpClient() { 
     def client = new HttpClient() 
    } 
} 

但是我不能讓它工作,因爲Grails是無法解決任何類。

我試過手動導入沒有成功。

我在做什麼錯了?

在此先感謝。

回答

3

您錯過了Commons HttpClient作爲依賴關係。

你應該添加到您的依賴關係:

test 'commons-httpclient:commons-httpclient:3.1' 

另外,一定要導入您的源代碼正確的類:

org.apache.commons.httpclient.HttpClient 
+0

我現在看到的是平時無聊的事情,但我仍花費相當多的時間試圖弄明白。通常的事情......謝謝。 – Rafael 2014-10-10 16:31:53