The Gradle plugin

The primary build tool used in this book is Maven. With Gradle getting more and more popular, it should be mentioned that OpenLiberty also provides full support for Gradle. The OpenLiberty Gradle plugin can be used in the following ways:

  • Apply the OpenLiberty Gradle plugin to the project.
  • Define the OpenLiberty.io runtime as a runtime dependency.
  • Instruct Gradle to invoke OpenLiberty with common Gradle goals.

It all starts the standard Gradle way, by applying a plugin:

apply plugin: 'liberty

The plugin must be made available to the build strict. A typical Gradle build script block contains a Maven central repository, as demonstrated here. In addition, the OpenLiberty's Gradle plugin is applied as a dependency on the classpath:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'net.wasdev.wlp.gradle.plugins:liberty-gradle-plugin:2.1'
    }
}

OpenLiberty does not force the resulting artifact to contain OpenLiberty-specific libraries. The OpenLiberty plugin introduces a special dependency scope, named libertyRuntime. The name is self-describing; it tells the reader such dependencies are only bundled inside the OpenLiberty runtime. Such a dependency is often accompanied by other dependencies. In the case of Java EE 8, the whole API may be included as a provided dependency:

dependencies{
providedCompile 'javax:javaee-api:8.0'
libertyRuntime group: 'io.openliberty', name: 'openliberty-runtime', version: '[17.0.0.4,)'
}

As in the case of Maven, OpenLiberty offers a convenient way to configure default properties. The properties are an exact copy of those described in the Maven section. The server name, default ports, context root, or name of resulting archive, everything may be reconfigured. Java EE 8 projects tend to evolve rapidly, so are OpenLiberty plugins for Gradle and Maven. For a complete list of features, configurables, and settings, please visit the reference guide at https://openliberty.io/docs/.

liberty {
    server {
        name = "$OpenLiberty Server"
        configFile = file("src/main/liberty/config/server.xml")
        bootstrapProperties = ['default.http.port': 8080,
                               'default.https.port': 8443,
                               'app.context.root': ${appName}]
        packageLiberty {
            archive = "$buildDir/${appName}.zip"
            include = "usr"
        }
    }
}

To run the application, the following Gradle tasks similar to Maven's goals are available:

libertyStart

libertyStop

..................Content has been hidden....................

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