barryalan2633
barryalan2633

Reputation: 840

Project 'fatjar' not found in root project

I am following this Ktor documentation but when I run

./gradlew :fatjar:shadowJar

on IntelliJ's terminal just like it says I get the following error:

FAILURE: Build failed with an exception.

  • What went wrong: Project 'fatjar' not found in root project 'com.menucabinet.ktor-menu-cabinet'.

I have been looking around but there seems to be limited documentation regarding this issue...

Here is my gradle:

val ktor_version: String by project
val kotlin_version: String by project
val logback_version: String by project
val kmongo_version: String by project
val koin_version: String by project

plugins {
    application
    kotlin("jvm") version "1.6.10"
    id("org.jetbrains.kotlin.plugin.serialization") version "1.6.10"
    id("com.github.johnrengelman.shadow") version "7.0.0"

}

group = "menu_cabinet"
version = "0.0.1"
application {
    mainClass.set("io.ktor.server.netty.EngineMain")
    project.setProperty("mainClassName", mainClass.get())
}

repositories {
    mavenCentral()
}

tasks {
    shadowJar {
        manifest {
            attributes(Pair("Main-Class", "io.ktor.server.netty.EngineMain"))
        }
    }
}
    
dependencies {
    implementation("io.ktor:ktor-server-core:$ktor_version")
    implementation("io.ktor:ktor-websockets:$ktor_version")
    implementation("io.ktor:ktor-serialization:$ktor_version")
    implementation("io.ktor:ktor-server-sessions:$ktor_version")
    implementation("io.ktor:ktor-server-netty:$ktor_version")
    implementation("ch.qos.logback:logback-classic:$logback_version")
    testImplementation("io.ktor:ktor-server-tests:$ktor_version")
    testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")

    // KMongo
    implementation("org.litote.kmongo:kmongo:$kmongo_version")
    implementation("org.litote.kmongo:kmongo-coroutine:$kmongo_version")

    // Koin core features
    implementation("io.insert-koin:koin-core:$koin_version")
    implementation("io.insert-koin:koin-ktor:$koin_version")
    implementation("io.insert-koin:koin-logger-slf4j:$koin_version")


}

I am new to Ktor and back ends in general, what can I do to fix this?

Update:

I have found that if I

  1. Add the following plugin to gradle id("com.github.johnrengelman.shadow") version "7.0.0"
  2. Open the Gradle menu on the top right of IntelliJ and find and select Tasks/shadow/shadowJar
  3. This will build the jar file and place it under build/libs in the project files
  4. I can then run the jar from the computer's terminal using java -jar theNameOftheGeneratedJarFile

So since this is working I believe my issue has to do with Gradle tasks in Kotlin DSL, though I could be wrong.

Upvotes: 0

Views: 815

Answers (2)

Hari
Hari

Reputation: 3

For standalone projects, running this from the terminal should build the jar file in the lib folder, here is a working sample https://github.com/hariinfo/ktor-learn/tree/main/ktor-exposed-demo

Upvotes: 0

Andrey Aksyonov
Andrey Aksyonov

Reputation: 331

The Gradle Shadow plugin topic uses the fatjar sample as an example. Given that this sample is a sub-project of codeSnippets, creating a fat JAR requires adding a sub-project name before the shadowJar task:

./gradlew :fatjar:shadowJar 

For a standalone project, this command looks like this:

./gradlew shadowJar

Upvotes: 1

Related Questions