如何从maven触发休息呼叫?

时间:2016-03-09 13:51:11

标签: java rest maven groovy

我正在搜索一个maven插件,可以在pre-integrate-test触发其余的来电。

我只需要一个能为我做这件事的插件。

目前我尝试使用groovy-maven-plugin version 2.0

            <plugin>
            <groupId>org.codehaus.gmaven</groupId>
            <artifactId>groovy-maven-plugin</artifactId>
            <version>2.0</version>
            <dependencies>
                <dependency>
                    <groupId>org.apache.ivy</groupId>
                    <artifactId>ivy</artifactId>
                    <version>2.3.0</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <source>${root.relative.path}/target/triggerCacheLoading.groovy</source>
                    </configuration>
                </execution>
            </executions>
        </plugin>

groovy文件:

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )
import groovyx.net.http.RESTClient

import static groovyx.net.http.ContentType.XML

solr = new RESTClient('http://localhost:8080/endpoint')

log.info "----------------------------------- START GROOVY REST CALL -----------------------------------";

def response = solr.post(
    contentType: XML,
    requestContentType: XML,
    body: { }
)
log.info "Solr response status: ${response.status}"

log.info "----------------------------------- END GROOVY REST CALL -----------------------------------";

我得到了:

[ERROR] Failed to execute goal org.codehaus.gmaven:groovy-maven-plugin:2.0:execute (default-cli) on project reg-reporting: Execution default-cli of goal org.codehaus.gmaven:groovy-maven-plugin:2.0:execute failed: A required class was missing while executing org.codehaus.gmaven:groovy-maven-plugin:2.0:execute: org/apache/ivy/core/report/ResolveReport
...
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 
[ERROR] -----------------------------------------------------: org.apache.ivy.core.report.ResolveReport

1 个答案:

答案 0 :(得分:1)

我不确定为什么你需要那里的常春藤依赖?让Maven管理所有依赖项,包括HTTP构建器,而不是使用Grape,这可能是一个好主意:

  <plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>groovy-maven-plugin</artifactId>
    <version>2.0</version>
    <executions>
      <execution>
        <id>cache-loading</id>
        <phase>pre-integration-test</phase>
        <goals>
          <goal>execute</goal>
        </goals>
        <configuration>
          <source>${root.relative.path}/target/triggerCacheLoading.groovy</source>
        </configuration>
      </execution>
    </executions>
    <dependencies>
      <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.4.6</version>
      </dependency>
      <dependency>
        <groupId>org.codehaus.groovy.modules.http-builder</groupId>
        <artifactId>http-builder</artifactId>
        <version>0.7.1</version>
      </dependency>
    </dependencies>
  </plugin>