Gradle settings

Gradle is an open source build automation tool that uses scripts written in Groovy or Kotlin DSL. It is supported by the major IDEs, and you can run it using command-line interfaces or through a continuous integration server.

Once installed, you can create a new project or automatically convert an existing Maven project into a Gradle one, by launching the following command from your project's root:

$ gradle init

In order to use Vert.x in a Gradle project, you can create a Gradle file, such as the following one:

plugins {
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '2.0.4'
}
ext {
vertxVersion = '3.5.4'
junitJupiterEngineVersion = '5.2.0'
}

repositories {
mavenLocal()
jcenter()
}

group = 'com.packtpub.vertx'
version = '1.0.0-SNAPSHOT'

sourceCompatibility = '1.8'
mainClassName = 'io.vertx.core.Launcher'

def mainVerticleName = 'com.packtpub.vertx.football-player-microservice.MainVerticle'
def watchForChange = 'src/**/*'
def doOnChange = './gradlew classes'

dependencies {
implementation "io.vertx:vertx-core:$vertxVersion"
implementation "io.vertx:vertx-config:$vertxVersion"
...
}

shadowJar {
classifier = 'fat'
manifest {
attributes 'Main-Verticle': mainVerticleName
}
mergeServiceFiles {
include 'META-INF/services/io.vertx.core.spi.VerticleFactory'
}
}
...
run {
args = ['run', mainVerticleName, "--redeploy=$watchForChange", "--launcher-
class=$mainClassName", "--on-redeploy=$doOnChange"]
}

...

This snippet will add a declaration of the Vert.x version as an external dependency—in this way, you don't need to have a specific version as these are implicitly defined in the BOM file.

To build the executable JAR, you can execute the following command:

$ ./gradlew shadowJar

After that, you can run it by executing the following command:

$ java -jar build/libs/gradle-my-vertx-project.jar

Alternatively, you can execute the following Gradle command instead:

$ ./gradlew run
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset