In a Kotlin Multiplatform project using Kotlin 1.4...
# fritz2
n
In a Kotlin Multiplatform project using Kotlin 1.4.31 (JS with IR and JVM without IR) there are two modules (webClient, and server). The webClient module causes the Fritz2 Gradle plugin to break with the following error message appearing:
Task with name 'compileKotlinJs' not found in root project
. If the webClient module is renamed to js then the error disappears, however a warning message appears:
Duplicate content roots detected
c
Could you provide us some more information please? Can you post a link to a github repo, which can be used to reproduce this behaviour out of the box? Or at least some gist with the gradle build files within? I really can't figure out, how to reproduce this just with this few infos, nor what the cause and the solution might be.
n
Below are the contents of the build file:
Copy code
group = "org.example"
version = "0.1-SNAPSHOT"

plugins {
    kotlin("multiplatform") version "1.4.31"
    id("dev.fritz2.fritz2-gradle") version "0.9"
    application
}

application {
    mainClass.set("io.ktor.server.netty.EngineMain")
}

repositories {
    mavenCentral()
}

kotlin {
    jvm("server") {
        dependencies {
            val ktorVer = "1.5.2"
            implementation("io.ktor:ktor-server-core:$ktorVer")
            implementation("io.ktor:ktor-server-netty:$ktorVer")
        }
        withJava()
    }

    js(name = "webClient", compiler = IR) {
        browser()
    }.binaries.executable()

    sourceSets {
        commonMain {
            dependencies {
                implementation("dev.fritz2:core:0.9")
            }
        }
    }
}
j
The problem with the first issue is, that we add a dependency to our kapt task by doing this in our gradle-plugin:
tasks.getByName("compileKotlinJs").dependsOn("kaptKotlinJvm")
When you change the name of the
js
or
jvm
multiplatform-target e.g. to
webClient
then this is not matching anymore... Therefore we need a more generic way to create this task-dependency with gradle. The second warning message comes from the line
withJava()
. When you remove that call the warning should disappear. This takes me some time to figure it out, but I don't know why this warning occours when using
withJava()
... ☹️
@napperley With the help of Jetbrains I found a solution for the first problem. It will be available in the next version 0.9.2 of fritz2 😉 Here is the PR for it: https://github.com/jwstegemann/fritz2-gradle-plugin/pull/8
👍 2
n
The
withJava
function is required in order to use the
application
Gradle plugin, which is used to run the Ktor based server. There doesn't appear to be a straightforward way to run the server, and have the Kotlin JS continuous feature running at the same time.
j
@napperley I can't confirm that. A while ago I had the same issues in my full-stack ktor example project https://github.com/jamowei/fritz2-ktor-todomvc and I successfully removed the
withJava
function there. The project works as expected without it and the warning of course disappers. Also, I don't use Java code in my project and therefore don't need the function
withJava
. As I understand it, it is there only for using Kotlin and Java together as described here.