我需要从gradle任务启动WireMock服务器。在Java中,我将执行以下操作:
WireMockServer wireMockServer = new WireMockServer(wireMockConfig().port(8089));
如何使用gradle任务创建该wireMock服务器?
最佳答案
可以完全相同的方式完成。这里有一个工作示例:
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
块的依赖项添加。