使用Gradle任务创建java类实例?

时间:2014-12-22 10:32:50

标签: groovy gradle

我需要从gradle任务启动WireMock服务器。在java中我会做这样的事情:

WireMockServer wireMockServer = new WireMockServer(wireMockConfig().port(8089));

如何使用gradle任务创建此wireMock服务器?

1 个答案:

答案 0 :(得分:1)

可以完全相同的方式完成。在这里你有一个工作的例子:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.github.tomakehurst:wiremock:1.52'
    }
}
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig
import com.github.tomakehurst.wiremock.*
apply plugin: 'java'

task someTask {

    doLast {
        WireMockServer wireMockServer = new WireMockServer(wireMockConfig().port(8089))
        println wireMockServer
    }
}

如果要在build.gradle本身使用外部库,则应将其作为依赖项添加到buildscript块。