From 75786c2704a5f2401c8a00526e2dca186905fd9f Mon Sep 17 00:00:00 2001 From: Alexander Sysoev Date: Tue, 19 Nov 2024 14:06:13 +0100 Subject: [PATCH] Update the project structure to work with kotlin-master --- .gitignore | 2 +- gradle-conventions-settings/build.gradle.kts | 10 ---- .../main/kotlin/util/KotlinVersionActions.kt | 46 +++++++++++++++++++ gradle-conventions/build.gradle.kts | 4 +- gradle-conventions/common/build.gradle.kts | 28 +++++++++++ .../src/main/kotlin/build-util.gradle.kts | 5 ++ .../common}/src/main/kotlin/util/Dir.kt | 0 .../common}/src/main/kotlin/util/JsTarget.kt | 0 .../src/main/kotlin/util/KotlinExtension.kt | 0 .../src/main/kotlin/util/KotlinVersion.kt | 38 --------------- .../main/kotlin/util/OptInForInternalApi.kt | 0 .../src/main/kotlin/util/OptionalProperty.kt | 0 .../common}/src/main/kotlin/util/Path.kt | 0 .../main/kotlin/util/ProjectKotlinConfig.kt | 0 .../src/main/kotlin/util/PublicModule.kt | 0 .../src/main/kotlin/util/PublicationUtils.kt | 0 .../src/main/kotlin/util/StringCase.kt | 0 .../src/main/kotlin/util/TargetUtils.kt | 0 .../src/main/kotlin/util/apiValidation.kt | 0 .../common}/src/main/kotlin/util/atomicfu.kt | 0 .../common}/src/main/kotlin/util/forIde.kt | 0 .../common}/src/main/kotlin/util/jvm.kt | 0 .../common}/src/main/kotlin/util/npm.kt | 0 .../src/main/kotlin/util/projectReport.kt | 0 .../src/main/kotlin/util/properties.kt | 0 .../latest-only/build.gradle.kts | 2 + gradle-conventions/settings.gradle.kts | 6 +-- .../util/contextReceivers.kt | 0 .../src/main/{latest => kotlin}/util/wasm.kt | 0 29 files changed, 85 insertions(+), 56 deletions(-) create mode 100644 gradle-conventions-settings/src/main/kotlin/util/KotlinVersionActions.kt create mode 100644 gradle-conventions/common/build.gradle.kts create mode 100644 gradle-conventions/common/src/main/kotlin/build-util.gradle.kts rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/Dir.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/JsTarget.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/KotlinExtension.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/KotlinVersion.kt (78%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/OptInForInternalApi.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/OptionalProperty.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/Path.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/ProjectKotlinConfig.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/PublicModule.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/PublicationUtils.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/StringCase.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/TargetUtils.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/apiValidation.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/atomicfu.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/forIde.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/jvm.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/npm.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/projectReport.kt (100%) rename {gradle-conventions-settings => gradle-conventions/common}/src/main/kotlin/util/properties.kt (100%) rename gradle-conventions/src/main/{latest => kotlin}/util/contextReceivers.kt (100%) rename gradle-conventions/src/main/{latest => kotlin}/util/wasm.kt (100%) diff --git a/.gitignore b/.gitignore index 32acf863..efa57df2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ # Ignore Gradle build output directory build .kotlin - +lib-kotlin # idea files .idea/* !.idea/runConfigurations diff --git a/gradle-conventions-settings/build.gradle.kts b/gradle-conventions-settings/build.gradle.kts index fa7384e4..4ac95498 100644 --- a/gradle-conventions-settings/build.gradle.kts +++ b/gradle-conventions-settings/build.gradle.kts @@ -15,17 +15,7 @@ configurations.configureEach { } } -val isLatestKotlinVersion: Boolean by extra - dependencies { - api(libs.kotlin.gradle.plugin) - api(libs.detekt.gradle.plugin) - api(libs.binary.compatibility.validator.gradle.plugin) - - if (isLatestKotlinVersion) { - api(libs.kover.gradle.plugin) - } - // https://stackoverflow.com/questions/76713758/use-version-catalog-inside-precompiled-gradle-plugin api(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) } diff --git a/gradle-conventions-settings/src/main/kotlin/util/KotlinVersionActions.kt b/gradle-conventions-settings/src/main/kotlin/util/KotlinVersionActions.kt new file mode 100644 index 00000000..3b3ede50 --- /dev/null +++ b/gradle-conventions-settings/src/main/kotlin/util/KotlinVersionActions.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package util + +import org.gradle.api.plugins.ExtensionAware +import org.gradle.kotlin.dsl.extra +import org.gradle.kotlin.dsl.provideDelegate + + +data class ActionApplied(val applied: Boolean) + +@Suppress("unused") +inline fun ExtensionAware.whenKotlinIsAtLeast( + major: Int, + minor: Int, + patch: Int = 0, + action: () -> Unit = {}, +): ActionApplied { + val kotlinVersion: KotlinVersion by extra + + if (kotlinVersion.isAtLeast(major, minor, patch)) { + action() + + return ActionApplied(true) + } + + return ActionApplied(false) +} + +inline fun ExtensionAware.whenKotlinLatest(action: () -> Unit): ActionApplied { + val isLatestKotlinVersion: Boolean by extra + + if (isLatestKotlinVersion) { + action() + } + + return ActionApplied(isLatestKotlinVersion) +} + +infix fun ActionApplied.otherwise(body: () -> Unit) { + if (!applied) { + body() + } +} diff --git a/gradle-conventions/build.gradle.kts b/gradle-conventions/build.gradle.kts index 25df9836..5c074a09 100644 --- a/gradle-conventions/build.gradle.kts +++ b/gradle-conventions/build.gradle.kts @@ -10,12 +10,10 @@ plugins { alias(libs.plugins.gradle.kotlin.dsl) } -// chicken-egg -apply(from = "src/main/kotlin/compiler-specific-module.gradle.kts") - defaultConventionConfiguration() dependencies { + implementation(project(":common")) implementation(":gradle-conventions-settings") project.whenKotlinLatest { diff --git a/gradle-conventions/common/build.gradle.kts b/gradle-conventions/common/build.gradle.kts new file mode 100644 index 00000000..d14cefe0 --- /dev/null +++ b/gradle-conventions/common/build.gradle.kts @@ -0,0 +1,28 @@ +/* + * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +import util.defaultConventionConfiguration + +plugins { + alias(libs.plugins.gradle.kotlin.dsl) +} + +defaultConventionConfiguration() + +val isLatestKotlinVersion: Boolean by extra + +dependencies { + implementation(":gradle-conventions-settings") + + api(libs.kotlin.gradle.plugin) + api(libs.detekt.gradle.plugin) + api(libs.binary.compatibility.validator.gradle.plugin) + + if (isLatestKotlinVersion) { + api(libs.kover.gradle.plugin) + } + + // https://stackoverflow.com/questions/76713758/use-version-catalog-inside-precompiled-gradle-plugin + api(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) +} diff --git a/gradle-conventions/common/src/main/kotlin/build-util.gradle.kts b/gradle-conventions/common/src/main/kotlin/build-util.gradle.kts new file mode 100644 index 00000000..a646b214 --- /dev/null +++ b/gradle-conventions/common/src/main/kotlin/build-util.gradle.kts @@ -0,0 +1,5 @@ +/* + * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +// empty diff --git a/gradle-conventions-settings/src/main/kotlin/util/Dir.kt b/gradle-conventions/common/src/main/kotlin/util/Dir.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/Dir.kt rename to gradle-conventions/common/src/main/kotlin/util/Dir.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/JsTarget.kt b/gradle-conventions/common/src/main/kotlin/util/JsTarget.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/JsTarget.kt rename to gradle-conventions/common/src/main/kotlin/util/JsTarget.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/KotlinExtension.kt b/gradle-conventions/common/src/main/kotlin/util/KotlinExtension.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/KotlinExtension.kt rename to gradle-conventions/common/src/main/kotlin/util/KotlinExtension.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/KotlinVersion.kt b/gradle-conventions/common/src/main/kotlin/util/KotlinVersion.kt similarity index 78% rename from gradle-conventions-settings/src/main/kotlin/util/KotlinVersion.kt rename to gradle-conventions/common/src/main/kotlin/util/KotlinVersion.kt index 6f363b5a..e63f9238 100644 --- a/gradle-conventions-settings/src/main/kotlin/util/KotlinVersion.kt +++ b/gradle-conventions/common/src/main/kotlin/util/KotlinVersion.kt @@ -4,8 +4,6 @@ package util -import org.gradle.api.plugins.ExtensionAware -import org.gradle.kotlin.dsl.extra import org.gradle.kotlin.dsl.provideDelegate import java.io.File import java.nio.file.Files @@ -87,39 +85,3 @@ private fun Collection.mostSpecificByVersionOrNull(kotlinVersion: KotlinVe // - pre_1_9_20 // etc. private val directoryNameRegex = "^(latest|(v|pre)(_\\d){1,3}\\d?)$".toRegex() - -data class ActionApplied(val applied: Boolean) - -@Suppress("unused") -inline fun ExtensionAware.whenKotlinIsAtLeast( - major: Int, - minor: Int, - patch: Int = 0, - action: () -> Unit = {}, -): ActionApplied { - val kotlinVersion: KotlinVersion by extra - - if (kotlinVersion.isAtLeast(major, minor, patch)) { - action() - - return ActionApplied(true) - } - - return ActionApplied(false) -} - -inline fun ExtensionAware.whenKotlinLatest(action: () -> Unit): ActionApplied { - val isLatestKotlinVersion: Boolean by extra - - if (isLatestKotlinVersion) { - action() - } - - return ActionApplied(isLatestKotlinVersion) -} - -infix fun ActionApplied.otherwise(body: () -> Unit) { - if (!applied) { - body() - } -} diff --git a/gradle-conventions-settings/src/main/kotlin/util/OptInForInternalApi.kt b/gradle-conventions/common/src/main/kotlin/util/OptInForInternalApi.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/OptInForInternalApi.kt rename to gradle-conventions/common/src/main/kotlin/util/OptInForInternalApi.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/OptionalProperty.kt b/gradle-conventions/common/src/main/kotlin/util/OptionalProperty.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/OptionalProperty.kt rename to gradle-conventions/common/src/main/kotlin/util/OptionalProperty.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/Path.kt b/gradle-conventions/common/src/main/kotlin/util/Path.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/Path.kt rename to gradle-conventions/common/src/main/kotlin/util/Path.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/ProjectKotlinConfig.kt b/gradle-conventions/common/src/main/kotlin/util/ProjectKotlinConfig.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/ProjectKotlinConfig.kt rename to gradle-conventions/common/src/main/kotlin/util/ProjectKotlinConfig.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/PublicModule.kt b/gradle-conventions/common/src/main/kotlin/util/PublicModule.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/PublicModule.kt rename to gradle-conventions/common/src/main/kotlin/util/PublicModule.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/PublicationUtils.kt b/gradle-conventions/common/src/main/kotlin/util/PublicationUtils.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/PublicationUtils.kt rename to gradle-conventions/common/src/main/kotlin/util/PublicationUtils.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/StringCase.kt b/gradle-conventions/common/src/main/kotlin/util/StringCase.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/StringCase.kt rename to gradle-conventions/common/src/main/kotlin/util/StringCase.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/TargetUtils.kt b/gradle-conventions/common/src/main/kotlin/util/TargetUtils.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/TargetUtils.kt rename to gradle-conventions/common/src/main/kotlin/util/TargetUtils.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/apiValidation.kt b/gradle-conventions/common/src/main/kotlin/util/apiValidation.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/apiValidation.kt rename to gradle-conventions/common/src/main/kotlin/util/apiValidation.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/atomicfu.kt b/gradle-conventions/common/src/main/kotlin/util/atomicfu.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/atomicfu.kt rename to gradle-conventions/common/src/main/kotlin/util/atomicfu.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/forIde.kt b/gradle-conventions/common/src/main/kotlin/util/forIde.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/forIde.kt rename to gradle-conventions/common/src/main/kotlin/util/forIde.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/jvm.kt b/gradle-conventions/common/src/main/kotlin/util/jvm.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/jvm.kt rename to gradle-conventions/common/src/main/kotlin/util/jvm.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/npm.kt b/gradle-conventions/common/src/main/kotlin/util/npm.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/npm.kt rename to gradle-conventions/common/src/main/kotlin/util/npm.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/projectReport.kt b/gradle-conventions/common/src/main/kotlin/util/projectReport.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/projectReport.kt rename to gradle-conventions/common/src/main/kotlin/util/projectReport.kt diff --git a/gradle-conventions-settings/src/main/kotlin/util/properties.kt b/gradle-conventions/common/src/main/kotlin/util/properties.kt similarity index 100% rename from gradle-conventions-settings/src/main/kotlin/util/properties.kt rename to gradle-conventions/common/src/main/kotlin/util/properties.kt diff --git a/gradle-conventions/latest-only/build.gradle.kts b/gradle-conventions/latest-only/build.gradle.kts index d0a52cd7..d92836c0 100644 --- a/gradle-conventions/latest-only/build.gradle.kts +++ b/gradle-conventions/latest-only/build.gradle.kts @@ -11,6 +11,8 @@ plugins { defaultConventionConfiguration() dependencies { + implementation(project(":common")) + implementation(":gradle-conventions-settings") implementation(libs.kotlin.gradle.plugin) implementation(libs.kover.gradle.plugin) diff --git a/gradle-conventions/settings.gradle.kts b/gradle-conventions/settings.gradle.kts index 0faac887..f6633b54 100644 --- a/gradle-conventions/settings.gradle.kts +++ b/gradle-conventions/settings.gradle.kts @@ -5,10 +5,6 @@ import util.otherwise import util.whenKotlinLatest -/* - * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - rootProject.name = "gradle-conventions" enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") @@ -24,6 +20,8 @@ plugins { id("conventions-version-resolution") } +include(":common") + whenKotlinLatest { include(":latest-only") } otherwise { diff --git a/gradle-conventions/src/main/latest/util/contextReceivers.kt b/gradle-conventions/src/main/kotlin/util/contextReceivers.kt similarity index 100% rename from gradle-conventions/src/main/latest/util/contextReceivers.kt rename to gradle-conventions/src/main/kotlin/util/contextReceivers.kt diff --git a/gradle-conventions/src/main/latest/util/wasm.kt b/gradle-conventions/src/main/kotlin/util/wasm.kt similarity index 100% rename from gradle-conventions/src/main/latest/util/wasm.kt rename to gradle-conventions/src/main/kotlin/util/wasm.kt