Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kotlin-compiler-embeddable dependencies should be compileOnly #407

Merged
merged 4 commits into from
Dec 21, 2024

Conversation

dkostyrev
Copy link

After upgrading kotlin version to 2.1.0 kotlin gradle plugin raises warning if kotlin-compiler-embeddable is present in the classpath:

w: The artifact `org.jetbrains.kotlin:kotlin-compiler-embeddable` is present in the build classpath along Kotlin Gradle plugin.
This may lead to unpredictable and inconsistent behavior.
For more details, see: https://kotl.in/gradle/internal-compiler-symbols

According to the output of buildEnvironment Gradle task compose-rules add kotlin-compiler-embeddable to the classpath:

\--- io.nlopez.compose.rules:ktlint:0.4.22
     +--- com.pinterest.ktlint:ktlint-rule-engine:1.4.1
     |    +--- com.pinterest.ktlint:ktlint-logger:1.4.1
     |    |    +--- dev.drewhamilton.poko:poko-annotations:0.17.2
     |    |    |    \--- dev.drewhamilton.poko:poko-annotations-jvm:0.17.2
     |    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:2.0.21 -> 2.1.0 (*)
     |    |    +--- io.github.oshai:kotlin-logging-jvm:7.0.0
     |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.0.0 -> 2.1.0 (*)
     |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.0.21 -> 2.1.0 (*)
     |    +--- dev.drewhamilton.poko:poko-annotations:0.17.2 (*)
     |    +--- com.pinterest.ktlint:ktlint-rule-engine-core:1.4.1
     |    |    +--- com.pinterest.ktlint:ktlint-logger:1.4.1 (*)
     |    |    +--- dev.drewhamilton.poko:poko-annotations:0.17.2 (*)
     |    |    +--- org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.21
     |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.21 -> 2.1.0 (*)
     |    |    |    +--- org.jetbrains.kotlin:kotlin-script-runtime:2.0.21
     |    |    |    +--- org.jetbrains.kotlin:kotlin-reflect:1.6.10 -> 1.9.24 (*)
     |    |    |    +--- org.jetbrains.kotlin:kotlin-daemon-embeddable:2.0.21
     |    |    |    +--- org.jetbrains.intellij.deps:trove4j:1.0.20200330
     |    |    |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4
     |    |    +--- org.ec4j.core:ec4j-core:1.1.0
     |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.0.21 -> 2.1.0 (*)
     |    +--- org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.21 (*)
     |    +--- org.ec4j.core:ec4j-core:1.1.0
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.0.21 -> 2.1.0 (*)
     +--- com.pinterest.ktlint:ktlint-cli-ruleset-core:1.4.1
     |    +--- dev.drewhamilton.poko:poko-annotations:0.17.2 (*)
     |    +--- com.pinterest.ktlint:ktlint-rule-engine-core:1.4.1 (*)
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.0.21 -> 2.1.0 (*)
     +--- io.nlopez.compose.rules:common:0.4.22
     |    +--- org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.21 (*)
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.0.21 -> 2.1.0 (*)
     \--- org.jetbrains.kotlin:kotlin-stdlib:2.0.21 -> 2.1.0 (*)

after proposed changes:

\--- io.nlopez.compose.rules:ktlint:0.4.23-compile-only
     +--- io.nlopez.compose.rules:common:0.4.23-compile-only
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)

@@ -5,7 +5,7 @@ plugins {
}

dependencies {
api(libs.kotlin.compiler)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work well when generating the fat jars for cli / ide plugins for detekt and ktlint.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I think that I can add separate Gradle configuration for shadowJar, but it will require adding transitive dependencies explicitly.

Example for detekt rules:

dependencies {
    api(libs.detekt.core)
    api(projects.rules.common)
    shadowJarInclude(libs.kotlin.compiler)
    // ...
}

What do you think?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiling with shadowjar can be detected in this project by the existence of the "uberJar" property.

In the build.gradle.kts for the detekt / ktlint projects, we are already checking it, so I guess we could do it in the dependencies block as well:

if (project.hasProperty("uberJar")) { 
  api(...)
} else {
  compileOnly(...)
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added custom configuration that checks if uberJar property is set and adds dependency as api and compileOnly otherwise.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed test dependencies, the check should pass now

@mrmans0n mrmans0n force-pushed the feature/kotlin-compileOnly branch from 07bd672 to 2e98f76 Compare December 19, 2024 20:40
@mrmans0n mrmans0n merged commit c9c5aec into mrmans0n:main Dec 21, 2024
2 checks passed
@dkostyrev dkostyrev deleted the feature/kotlin-compileOnly branch December 23, 2024 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants