DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Java
  4. Installing Features From Maven Dependencies in Open Liberty 18.0.0.2

Installing Features From Maven Dependencies in Open Liberty 18.0.0.2

We look at a tutorial on how to work with Maven and Gradle using the Open Liberty framework for building microservices.

Eric Lau user avatar by
Eric Lau
·
Jan. 29, 19 · Tutorial
Like (1)
Save
Tweet
Share
7.63K Views

Join the DZone community and get the full member experience.

Join For Free

Open Liberty 18.0.0.2 is available in several runtime packages, including as a kernel without any runtime features. With the latest releases of the Liberty Maven and Gradle plugins, you can install features to build up the runtime with exactly what you need. This can be done simply by adding feature dependencies in your build. The feature dependencies also provide the relevant dependencies for compiling your application, so there is no longer any need to add Liberty API, SPI, or Java specification dependencies.

The Runtime Kernel

If you’re using Maven, here are the coordinates for the runtime kernel:

<assemblyArtifact>
  <groupId>io.openliberty</groupId>
  <artifactId>openliberty-kernel</artifactId>
  <version>18.0.0.2</version>
  <type>zip</type>
</assemblyArtifact>

For Gradle:

dependencies {
   libertyRuntime 'io.openliberty:openliberty-kernel:18.0.0.2'
}

Dependencies

The Open Liberty 18.0.0.2 features are available on Maven Central under the io.openliberty.features groupId. When features are listed as dependencies, they will be installed by the Maven or Gradle plugin as well as provide Liberty API, SPI, and Java specification dependencies for compilation. Features can also continue to be listed as before in the plugin configuration/attributes or in the server.xml file, in which case those features will also be retrieved from Maven Central for installation. As with all Maven dependencies, the features that are retrieved from Maven or Gradle will be stored locally allowing for offline builds.

Maven

The features-bom artifact provides the bill of materials (BOM) for each release version and can be imported in the dependencyManagement section. This allows each feature to be listed in the dependencies section without needing to specify the version.

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.openliberty.features</groupId>
                <artifactId>features-bom</artifactId>
                <version>18.0.0.2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>io.openliberty.features</groupId>
            <artifactId>jaxrs-2.1</artifactId>
            <type>esa</type>
            <scope>provided</scope>
        </dependency>
    </dependencies>

Gradle

Use the libertyFeature dependency configuration to install features. If you are using the java plugin, then the libertyFeatureconfiguration extends from the java plugin’s compileOnly configuration to provide Liberty API, SPI, and Java specification dependencies as well.

dependencies {
   libertyFeature 'io.openliberty.features:jaxrs-2.1:18.0.0.2'
}

Putting it all together

Now that we’ve introduced the various parts, here’s how they fit together.

Maven

With Maven, import the BOM, specify feature dependencies, and configure the plugin with the install-server and install-featuregoals.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    ...
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.openliberty.features</groupId>
                <artifactId>features-bom</artifactId>
                <version>18.0.0.2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>io.openliberty.features</groupId>
            <artifactId>jaxrs-2.1</artifactId>
            <type>esa</type>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>net.wasdev.wlp.maven.plugins</groupId>
                <artifactId>liberty-maven-plugin</artifactId>
                <version>2.5</version>
                <executions>
                    <execution>
                        <id>install-server</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>install-server</goal>
                        </goals>
                        <configuration>
                            <assemblyArtifact>
                                <groupId>io.openliberty</groupId>
                                <artifactId>openliberty-kernel</artifactId>
                                <version>18.0.0.2</version>
                                <type>zip</type>
                            </assemblyArtifact>
                        </configuration>
                    </execution>
                    <execution>
                        <id>install-feature</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>install-feature</goal>
                        </goals>
                        <configuration>
                            <features>
                                <acceptLicense>true</acceptLicense>
                            </features>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Gradle

With Gradle, specify the libertyRuntime and libertyFeature dependencies.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath group: 'net.wasdev.wlp.gradle.plugins', name: 'liberty-gradle-plugin', version: '2.5'
    }
}

apply plugin: 'liberty'

repositories {
    mavenCentral()
}

dependencies {
   libertyRuntime 'io.openliberty:openliberty-kernel:18.0.0.2'
   libertyFeature 'io.openliberty.features:jaxrs-2.1:18.0.0.2'
}

liberty {
    server {
        features {
            acceptLicense = true
        }
    }
}

Further Reading

For more details on installing features from dependencies, refer to the readmes of the install-feature Maven goal or installFeature Gradle task.

Dependency Apache Maven

Published at DZone with permission of Eric Lau, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Best Practices for Writing Clean and Maintainable Code
  • RabbitMQ vs. Memphis.dev
  • PHP vs React
  • Building a Scalable Search Architecture

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: