Home > Back-end >  Add plugins to an existing Ktor project
Add plugins to an existing Ktor project

Time:11-01

I am learning Kotlin for backend.
I am using Ktor, and following tutorials on ktor.io website.

I am using IntelliJ IDEA CE (Community Edition), so I do not have access to Ktor configuration page nor plugins page (available on IntelliJ IDEA Ultimate, a premium edition).

I have to use the web based project generator, which asks me all the plugins I will need.

However, I might not know which plugins I will need : my project can grow, and I might need more plugins later.

Is there an efficient way to add plugins to an already existing project ?

CodePudding user response:

The best way I can recommend is to read the official documentation where you can find descriptions for all standard plugins and how to add them to a project.

CodePudding user response:

Go to your build.gradle.kts file in project. There you have a plugin and a dependencies block.

plugins {
application
kotlin("jvm") version "1.7.20"
id("io.ktor.plugin") version "2.1.2"
kotlin("plugin.serialization") version "1.7.20"
id("org.jlleitschuh.gradle.ktlint") version "11.0.0"
}

....

dependencies {
implementation("io.ktor:ktor-server-core-jvm:$ktor_version")
implementation("io.ktor:ktor-server-freemarker-jvm:$ktor_version")
implementation("io.ktor:ktor-server-host-common-jvm:$ktor_version")
implementation("io.ktor:ktor-server-netty-jvm:$ktor_version")
implementation("io.ktor:ktor-serialization:$ktor_version")
implementation("ch.qos.logback:logback-classic:$logback_version")
implementation("io.ktor:ktor-server-content-negotiation-jvm:2.1.2")
implementation("io.ktor:ktor-serialization-jackson:$ktor_version")
testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-cio:$ktor_version")
implementation("io.ktor:ktor-client-logging:$ktor_version")
implementation("io.ktor:ktor-client-serialization:$ktor_version")
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
implementation("io.ktor:ktor-server-content-negotiation:$ktor_version")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
implementation("org.jetbrains.exposed:exposed-core:$exposed_version")
implementation("org.jetbrains.exposed:exposed-dao:$exposed_version")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposed_version")
implementation("com.h2database:h2:$h2_version")

// Testing
testImplementation("org.junit.jupiter:junit-jupiter:$junitVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
testImplementation("org.assertj:assertj-core:3.23.1")
}

The correct line for implantation you will find usually on the specific webpage of the Ktor documentation. After adding some lines in there you should press the gradle update button which appears when something changes in this file.

  • Related