我们目前在多个内部和外部项目中使用Vert.x。 在最近的项目之前,我们一直在使用Maven构建Vert.x模块。
Gradle是我们选择的构建工具,但是Vert.x网站上描述的默认方法导致了几个问题:
- 克隆,清理和配置模板项目的任务容易出错。
- 模板项目不支持最新的Gradle版本> = 2.x;
- 此方法与IntelliJ IDEA中的Gradle支持不兼容。
在开始我们最近的项目时,我们研究了再次使用Gradle的可能性。 而不是使用Vert.x网站上描述的方法,而是使用Daryl Teo提供的出色的Vert.x Gradle插件 。
使用以下Gradle构建文件,我们能够从Gradle构建并运行我们的项目,并将其成功导入IntelliJ IDEA:
build.gradle
// Configure the dependencies for our build script
buildscript {
repositories {
jcenter()
}
dependencies {
// Specify our dependency on the marvelous plugin from Daryl Teo
classpath 'com.darylteo.vertx:vertx-gradle-plugin:0.1.3'
}
}
// Apply the Groovy plugin to compile our Groovy code
apply plugin: 'groovy'
// Apply the Vertx plugin
apply plugin: 'vertx'
repositories {
jcenter()
}
// Specify the project dependencies
dependencies {
compile "org.codehaus.groovy:groovy-all:2.3.3"
}
// Configure Vertx
vertx {
platform {
// Specify Vert.x version
version '2.1.5'
// Language used
lang 'groovy'
}
// Configuration of the module using Vert.x fields using camelcased names
// See: http://vertx.io/mods_manual.html#module-descriptor-file-modjson
config {
main 'groovy:com.jdriven.demo.MainVerticle'
}
// Specify the config file to pass to Vert.x using -conf when executing the runMod task
deployments {
mod {
platform {
conf 'config/vertx/dev.json'
}
}
}
}
使用此配置将公开以下与Vert.x相关的Gradle任务:
- modZip:创建模块zip
- debugMod:运行模块,包括远程调试
- runMod:运行模块
有关此奇妙的Gradle Vert.x插件的更多信息,请访问: https : //github.com/darylteo/vertx-gradle-plugin 。
请注意,Vert.x Gradle插件的功劳完全归于Daryl Teo。 这篇文章仅是为了提高人们对插件存在的认识,并补充他的出色工作。
翻译自: https://www.javacodegeeks.com/2015/03/building-vert-x-projects-using-gradle.html