Skip to content

Commit

Permalink
Migrating to gradle version catalog (#48)
Browse files Browse the repository at this point in the history
* Migrating to Gradle Version catalog

* Migrating to gradle version catalog
* Bumping gradle to 7.2
* Removed Deps

thanks @efemoney for the huge contribution
  • Loading branch information
MarcoSignoretto authored Aug 19, 2021
1 parent 2581e32 commit 514aa6b
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 114 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ private void setupJvmTarget(Project project) {

jvmTest {
dependencies {
implementation Deps.junit.junit
implementation libs.junit.junit
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
72 changes: 0 additions & 72 deletions buildSrc/buildSrc/src/main/kotlin/Deps.kt

This file was deleted.

45 changes: 45 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<DependenciesAccessors>().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) }
}
}
4 changes: 3 additions & 1 deletion buildSrc/src/main/kotlin/JsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,7 +42,7 @@ abstract class JsPlugin : Plugin<Project> {

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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion jacoco.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
apply plugin: 'jacoco'

jacoco {
toolVersion = Deps.jacocoVersion
toolVersion = libs.versions.jacoco.get()
}

subprojects {
Expand Down
8 changes: 4 additions & 4 deletions mockingbird/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -37,7 +37,7 @@ kotlin {
jsMain {
dependsOn jvmJsCommonMain
dependencies {
implementation Deps.kotlin.test.js
implementation libs.kotlin.test.js
}
}

Expand Down
17 changes: 0 additions & 17 deletions settings.gradle

This file was deleted.

17 changes: 11 additions & 6 deletions buildSrc/buildSrc/build.gradle.kts → settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
}
18 changes: 18 additions & 0 deletions versions.toml
Original file line number Diff line number Diff line change
@@ -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" }

0 comments on commit 514aa6b

Please sign in to comment.