From c9c5aecb6d708f854c2a6f47ea7ef65adf61803b Mon Sep 17 00:00:00 2001 From: Dmitrii Kostyrev <183590+dkostyrev@users.noreply.github.com> Date: Sat, 21 Dec 2024 21:21:49 +0000 Subject: [PATCH] kotlin-compiler-embeddable dependencies should be compileOnly (#407) * Ktlint and kotlin compiler should be compileOnly dependencies. * Introduce compileOnlyOrApi configuration that adds dependency as api if uberJar property is set. * Make testImplementation extend compileOnlyOrApi. * Add kotlin compiler explicitly to detekt rules testImplementation. --- build.gradle.kts | 13 +++++++++++++ rules/common/build.gradle.kts | 2 +- rules/detekt/build.gradle.kts | 3 ++- rules/ktlint/build.gradle.kts | 4 ++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 265d1793..46fffd5f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -54,6 +54,19 @@ allprojects { if (project != rootProject) { pluginManager.apply(libs.plugins.mavenPublish.get().pluginId) } + + project.configurations.create("compileOnlyOrApi") { + isCanBeConsumed = false + isCanBeResolved = true + + project.configurations.configureEach { + when { + name == "api" && project.hasProperty("uberJar") -> extendsFrom(this@create) + name == "compileOnly" -> extendsFrom(this@create) + name == "testImplementation" -> extendsFrom(this@create) + } + } + } } tasks.register("printVersion") { diff --git a/rules/common/build.gradle.kts b/rules/common/build.gradle.kts index dc90783a..1ad45683 100644 --- a/rules/common/build.gradle.kts +++ b/rules/common/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } dependencies { - api(libs.kotlin.compiler) + compileOnlyOrApi(libs.kotlin.compiler) testImplementation(libs.junit5) testImplementation(libs.junit5.params) diff --git a/rules/detekt/build.gradle.kts b/rules/detekt/build.gradle.kts index d1b64658..67bafb70 100644 --- a/rules/detekt/build.gradle.kts +++ b/rules/detekt/build.gradle.kts @@ -25,7 +25,7 @@ tasks.shadowJar { dependencies { api(libs.detekt.core) - api(projects.rules.common) + compileOnlyOrApi(projects.rules.common) testImplementation(libs.detekt.test) testImplementation(libs.junit5) @@ -34,4 +34,5 @@ dependencies { testImplementation(libs.reflections) testImplementation(libs.kaml) testImplementation(libs.konsist) + testImplementation(libs.kotlin.compiler) } diff --git a/rules/ktlint/build.gradle.kts b/rules/ktlint/build.gradle.kts index 8ccb2b87..556ce5d8 100644 --- a/rules/ktlint/build.gradle.kts +++ b/rules/ktlint/build.gradle.kts @@ -23,8 +23,8 @@ tasks.shadowJar { } dependencies { - api(libs.ktlint.rule.engine) - api(libs.ktlint.cli.ruleset.core) + compileOnlyOrApi(libs.ktlint.rule.engine) + compileOnlyOrApi(libs.ktlint.cli.ruleset.core) api(projects.rules.common) testImplementation(libs.ktlint.test)