Giter VIP home page Giter VIP logo

ktor-build-plugins's Introduction

Ktor Gradle plugin

This plugin simplifies the deployment process of server Ktor applications and provides the following capabilities:

  • Building fat JARs.
  • Dockerizing your applications.

Install the plugin

To install the plugin, add it to the plugins block of your build.gradle.kts:

plugins {
    id("io.ktor.plugin") version "2.3.11"
}

or build.gradle file:

plugins {
    id "io.ktor.plugin" version "2.3.11"
}

EAP builds

You can also use EAP versions of the plugin published on Space Packages. To do this, consider adding https://maven.pkg.jetbrains.space/public/p/ktor/eap to the list of plugin repositories in the settings.gradle file, which may look like this:

pluginManagement {
    repositories {
        gradlePluginPortal()
        maven("https://maven.pkg.jetbrains.space/public/p/ktor/eap")
    }
}

Build a fat JAR

To build and run a fat JAR, use the buildFatJar/runFatJar tasks. Note that a main class should be configured for your application, for example:

// build.gradle.kts
application {
    mainClass.set("com.example.ApplicationKt")
}

After the task is executed, you should see the ***-all.jar file in the build/libs directory. You can optionally configure the name of the fat JAR to be generated:

// build.gradle.kts
ktor {
    fatJar {
        archiveFileName.set("fat.jar")
    }
}

You can find a sample build script here: ktor-fatjar-sample/build.gradle.kts.

Dockerize your application

The following tasks are available for packaging, running, and deploying your application using Docker:

  • buildImage: builds a project's Docker image to a tarball. This task generates a ***.tar file in the build directory. You can load this image to a Docker daemon using the docker load command.
  • runDocker: builds a project's image to a Docker daemon and runs it.
  • publishImageToLocalRegistry: builds and publishes a project's Docker image to a local registry.
  • publishImage: builds and publishes a project's Docker image to an external registry. Note that you need to configure the external registry using the ktor.docker.externalRegistry property for this task.

A sample configuration for Docker-related tasks might look as follows:

// build.gradle.kts
ktor {
    docker {
        jreVersion.set(JreVersion.JRE_17)
        localImageName.set("sample-docker-image")
        imageTag.set("0.0.1-preview")

        externalRegistry.set(
            DockerImageRegistry.dockerHub(
                appName = provider { "ktor-app" },
                username = providers.environmentVariable("DOCKER_HUB_USERNAME"),
                password = providers.environmentVariable("DOCKER_HUB_PASSWORD")
            )
        )
    }
}

You can find a sample build script here: ktor-docker-sample/build.gradle.kts.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.