From 514aa6bb6f4ee14489077ff715b42843206bfcb5 Mon Sep 17 00:00:00 2001 From: Marco Signoretto Date: Thu, 19 Aug 2021 15:32:41 +0200 Subject: [PATCH] Migrating to gradle version catalog (#48) * Migrating to Gradle Version catalog * Migrating to gradle version catalog * Bumping gradle to 7.2 * Removed Deps thanks @efemoney for the huge contribution --- CHANGELOG.md | 2 + build.gradle | 10 +-- buildSrc/build.gradle.kts | 8 +-- buildSrc/buildSrc/src/main/kotlin/Deps.kt | 72 ------------------- buildSrc/settings.gradle.kts | 45 ++++++++++++ buildSrc/src/main/kotlin/JsPlugin.kt | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- jacoco.gradle | 2 +- mockingbird/build.gradle | 8 +-- settings.gradle | 17 ----- .../build.gradle.kts => settings.gradle.kts | 17 +++-- versions.toml | 18 +++++ 12 files changed, 91 insertions(+), 114 deletions(-) delete mode 100644 buildSrc/buildSrc/src/main/kotlin/Deps.kt create mode 100644 buildSrc/settings.gradle.kts delete mode 100644 settings.gradle rename buildSrc/buildSrc/build.gradle.kts => settings.gradle.kts (75%) create mode 100644 versions.toml diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cfec42..fc5e706 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. --- ## master +* Migrating to Gradle Version Catalog and removed Deps +* Bump gradle to 7.2 ## 1.11.0 * Enabled warnings as errors diff --git a/build.gradle b/build.gradle index f93c6be..0e54323 100644 --- a/build.gradle +++ b/build.gradle @@ -24,8 +24,8 @@ buildscript { maven { url "https://plugins.gradle.org/m2/" } } dependencies { - classpath Deps.kotlin.plugin - classpath Deps.jacoco + classpath libs.kotlinx.atomicfu.gradle + classpath libs.jacoco.jacoco } } @@ -58,8 +58,8 @@ void setupMultiplatformLibrary(Project project, Boolean shouldPublish = true) { sourceSets { commonTest { dependencies { - implementation Deps.kotlin.test - implementation Deps.kotlin.test.annotationsCommon + implementation libs.kotlin.test + implementation libs.kotlin.test.annotations } } } @@ -105,7 +105,7 @@ private void setupJvmTarget(Project project) { jvmTest { dependencies { - implementation Deps.junit.junit + implementation libs.junit.junit } } } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index b391b5c..56a79ab 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -23,12 +23,6 @@ repositories { gradlePluginPortal() } - dependencies { - implementation(Deps.kotlin.plugin) -} - -kotlin { - // Add Deps to compilation, so it will become available in main project - sourceSets.getByName("main").kotlin.srcDir("buildSrc/src/main/kotlin") + implementation(libs.kotlin.gradle) } diff --git a/buildSrc/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/buildSrc/src/main/kotlin/Deps.kt deleted file mode 100644 index 6d77dea..0000000 --- a/buildSrc/buildSrc/src/main/kotlin/Deps.kt +++ /dev/null @@ -1,72 +0,0 @@ -/** - * - * Copyright Careem, an Uber Technologies Inc. company - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -object Deps { - - private const val kotlinVersion = "1.5.21" - private const val junitVersion = "4.13.1" - - val kotlin = Kotlin - val kotlinx = Kotlinx - val touchlab = TouchLab - val junit = JUnit - - // Jacoco - private const val jacocoVersion = "0.8.7" - const val jacoco = "org.jacoco:org.jacoco.core:$jacocoVersion" - - object TouchLab { - val stately = Stately - - object Stately { - private const val statelyVersion = "1.1.7-a1" - - val isolate = Isolate - - object Isolate { - const val common = "co.touchlab:stately-isolate:$statelyVersion" - } - } - } - - object Kotlinx { - val atomicfu = AtomicFu - - object AtomicFu { - private const val atomicFuVersion = "0.16.2" - const val plugin = "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicFuVersion" - const val common = "org.jetbrains.kotlinx:atomicfu:$atomicFuVersion" - } - } - - object Kotlin { - val test = Test() - const val plugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" - - class Test(private val name: String = "org.jetbrains.kotlin:kotlin-test:$kotlinVersion") : - CharSequence by name { - val annotationsCommon = - "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlinVersion" - val js = "org.jetbrains.kotlin:kotlin-test-js:$kotlinVersion" - - override fun toString() = name - } - } - - object JUnit { - val junit = "junit:junit:$junitVersion" - } -} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 0000000..d212f3f --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,45 @@ +import org.gradle.initialization.DependenciesAccessors +import org.gradle.kotlin.dsl.support.serviceOf + +/** + * + * Copyright Careem, an Uber Technologies Inc. company + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +enableFeaturePreview("VERSION_CATALOGS") + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../versions.toml")) + } + } +} + + +gradle.rootProject { + val accessors = files(serviceOf().classes.asFiles) + + // To silent the IDE missing import + buildscript { dependencies.classpath(accessors) } + + // To add version catalog as plugin dependency + configurations + .matching { it.name == "implementation" } + .configureEach { + val implementation = this + dependencies { implementation(accessors) } + } +} diff --git a/buildSrc/src/main/kotlin/JsPlugin.kt b/buildSrc/src/main/kotlin/JsPlugin.kt index b79acf3..39ec42a 100644 --- a/buildSrc/src/main/kotlin/JsPlugin.kt +++ b/buildSrc/src/main/kotlin/JsPlugin.kt @@ -17,6 +17,8 @@ import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.artifacts.VersionCatalogsExtension +import org.gradle.kotlin.dsl.getByType import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile @@ -40,7 +42,7 @@ abstract class JsPlugin : Plugin { sourceSets.getByName("jsTest") { dependencies { - implementation(Deps.kotlin.test.js) + implementation("org.jetbrains.kotlin:kotlin-test-js:1.5.21") // FIXME to investigate how to use version catalog here as well } } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 29e4134..a0f7639 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/jacoco.gradle b/jacoco.gradle index e86d7ca..3bdf365 100644 --- a/jacoco.gradle +++ b/jacoco.gradle @@ -17,7 +17,7 @@ apply plugin: 'jacoco' jacoco { - toolVersion = Deps.jacocoVersion + toolVersion = libs.versions.jacoco.get() } subprojects { diff --git a/mockingbird/build.gradle b/mockingbird/build.gradle index 70ca366..9276ab9 100644 --- a/mockingbird/build.gradle +++ b/mockingbird/build.gradle @@ -22,9 +22,9 @@ kotlin { sourceSets { commonMain { dependencies { - implementation Deps.kotlinx.atomicfu.common - implementation Deps.touchlab.stately.isolate.common - implementation Deps.kotlin.test + implementation libs.kotlinx.atomicfu + implementation libs.touchlab.stately.isolate + implementation libs.kotlin.test } } @@ -37,7 +37,7 @@ kotlin { jsMain { dependsOn jvmJsCommonMain dependencies { - implementation Deps.kotlin.test.js + implementation libs.kotlin.test.js } } diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 47f367f..0000000 --- a/settings.gradle +++ /dev/null @@ -1,17 +0,0 @@ -/** - * - * Copyright Careem, an Uber Technologies Inc. company - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -include ':mockingbird' \ No newline at end of file diff --git a/buildSrc/buildSrc/build.gradle.kts b/settings.gradle.kts similarity index 75% rename from buildSrc/buildSrc/build.gradle.kts rename to settings.gradle.kts index eb40cef..8f8f54c 100644 --- a/buildSrc/buildSrc/build.gradle.kts +++ b/settings.gradle.kts @@ -14,10 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -plugins { - `kotlin-dsl` -} -repositories { - mavenCentral() -} +enableFeaturePreview("VERSION_CATALOGS") + +include(":mockingbird") + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("versions.toml")) + } + } +} \ No newline at end of file diff --git a/versions.toml b/versions.toml new file mode 100644 index 0000000..0b1c645 --- /dev/null +++ b/versions.toml @@ -0,0 +1,18 @@ +[versions] +kotlin = "1.5.21" +junit = "4.13.1" +jacoco = "0.8.7" +stately = "1.1.7-a1" +atomicFu = "0.16.2" + +[libraries] +jacoco-jacoco = { module = "org.jacoco:org.jacoco.core", version.ref = "jacoco" } +touchlab-stately-isolate = { module = "co.touchlab:stately-isolate", version.ref = "stately" } +kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "atomicFu" } +kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } +kotlin-test-annotations = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "kotlin" } +kotlin-test-js = { module = "org.jetbrains.kotlin:kotlin-test-js", version.ref = "kotlin" } +junit-junit = { module = "junit:junit", version.ref = "junit" } + +kotlinx-atomicfu-gradle = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicFu" } +kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } \ No newline at end of file