https://kotlinlang.org logo
g

georgi

09/20/2022, 7:24 AM
Hi there! Is adding a dependency as
implementation
currently the same as
api
on KotlinJS using the IR compiler? Documentation says standard gradle dependency declarations are supported. Example: I have 3 modules with the following dependency graph:
appJs
->
modulea
->
moduleb
, where I use
implementation
for linking between the modules. So
modulea
declares
implementation(project(":moduleb"))
. However, I can still access code within
mobuleb
from
appJs
which means that it's being leaked.
1
I'll list my
build.gradle.kts
files for reference in the thread.
Module
appJs
Copy code
plugins {
    kotlin("js") version "1.7.20-RC"
}

kotlin {
    js(IR) {
        binaries.executable()
        nodejs()
    }

    sourceSets {
        val main by getting {
            dependencies {
                implementation(project(":modulea"))
            }
        }
    }
}

dependencies {
    testImplementation(kotlin("test"))
}
Copy code
plugins {
    kotlin("js") version "1.7.20-RC"
}

kotlin {
    js(IR) {
        nodejs()
    }

    sourceSets {
        val main by getting {
            dependencies {
                implementation(project(":moduleb"))
            }
        }
    }
}

dependencies {
    testImplementation(kotlin("test"))
}
Module
moduleb
Copy code
plugins {
    kotlin("js") version "1.7.20-RC"
}

kotlin {
    js(IR) {
        nodejs()
    }
}

dependencies {
    testImplementation(kotlin("test"))
}
Hmm reading the gradle docs around dependencies, it seems that the
project(:modulea)
dependency is a special form of an execution dependency, where we're essentially saying that we want to depend on the output of
modulea
which in turn depends on the output of
moduleb
. Therefore all compiled classes will be added both to the
runtime
and
compiletime
classpath of
appJs
, which makes sense. I will try to add an external dependency as
implementation
to
moduleb
and see if it's leaking. I expect it shouldn't...
Seeing the same even with an external dependency 🤔
I was about to submit a bug report on YouTrack when I found a similar one which explains the issue. https://youtrack.jetbrains.com/issue/KT-51924/MPP-Gradle-library-sub-project-has-access-to-implementation-dependency
The situation around Kotlin/Native is a bit different than around the JVM world. Kotlin/Native doesn't support
compileOnly
or
runtimeOnly
dependencies.
It is required to pass all transitive dependencies in order to compile code even if it doesn't use symbols from some of them. This is known limitation of Kotlin/Native compiler. Theoretically the example above should be able to compile and Kotlin/Native team will be working on supporting cases like this at some point of time.
(Thought I'd share in case anyone stumbles across this in the future)
👍 1
3 Views