From 803cac3b69905c52a20364cf90ab86738cd413c9 Mon Sep 17 00:00:00 2001 From: Marco Signoretto Date: Wed, 17 Nov 2021 10:10:01 +0400 Subject: [PATCH] Migrated build gradle to Kts (#104) --- CHANGELOG.md | 1 + build.gradle => build.gradle.kts | 16 +++--- .../{build.gradle => build.gradle.kts} | 18 +++--- .../{build.gradle => build.gradle.kts} | 15 +++-- .../sample/{build.gradle => build.gradle.kts} | 17 +++--- samples/sample/build.gradle | 51 ----------------- samples/sample/build.gradle.kts | 55 +++++++++++++++++++ utils.gradle | 22 +++----- 8 files changed, 101 insertions(+), 94 deletions(-) rename build.gradle => build.gradle.kts (70%) rename mockingbird/{build.gradle => build.gradle.kts} (63%) rename samples/common-sample/{build.gradle => build.gradle.kts} (65%) rename samples/common/sample/{build.gradle => build.gradle.kts} (65%) delete mode 100644 samples/sample/build.gradle create mode 100644 samples/sample/build.gradle.kts diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f3b1ee..8fa4486 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. --- ## master +* Converted `build.gradle`s to `build.gradle.kts` ## 2.0.0 * Upgrade kotlin to 1.5.31 in JsPlugin diff --git a/build.gradle b/build.gradle.kts similarity index 70% rename from build.gradle rename to build.gradle.kts index f43ce02..9be7eb6 100644 --- a/build.gradle +++ b/build.gradle.kts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -apply from: 'jacoco.gradle' +apply(from= "jacoco.gradle") buildscript { repositories { @@ -22,23 +22,21 @@ buildscript { google() } dependencies { - classpath libs.kotlinx.atomicfu.gradle - classpath libs.jacoco.jacoco + classpath(libs.kotlinx.atomicfu.gradle) + classpath(libs.jacoco.jacoco) } } allprojects { - group GROUP - version VERSION + group = findProperty("GROUP") as String + version = findProperty("VERSION") as String repositories { mavenCentral() google() } - tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { - kotlinOptions{ - allWarningsAsErrors = true - } + tasks.withType().configureEach { + kotlinOptions.allWarningsAsErrors = true } } \ No newline at end of file diff --git a/mockingbird/build.gradle b/mockingbird/build.gradle.kts similarity index 63% rename from mockingbird/build.gradle rename to mockingbird/build.gradle.kts index 1ef6dc1..8e43b61 100644 --- a/mockingbird/build.gradle +++ b/mockingbird/build.gradle.kts @@ -14,20 +14,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import groovy.lang.Closure -apply from: '../utils.gradle' +plugins{ + id("org.jetbrains.kotlin.multiplatform") +} -setupMultiplatformLibrary(project, true) -setupAllTargetsWithDefaultSourceSets(project, true) +apply(from = "../utils.gradle") +val setupMultiplatformLibrary: Closure by ext +setupMultiplatformLibrary(project, true, true) kotlin { explicitApi() sourceSets { - commonMain { + val commonMain by getting { dependencies { - implementation libs.kotlinx.atomicfu - implementation libs.touchlab.stately.isolate - implementation libs.kotlin.test + implementation(libs.kotlinx.atomicfu) + implementation(libs.touchlab.stately.isolate) + implementation(libs.kotlin.test) } } } diff --git a/samples/common-sample/build.gradle b/samples/common-sample/build.gradle.kts similarity index 65% rename from samples/common-sample/build.gradle rename to samples/common-sample/build.gradle.kts index f2063eb..6878152 100644 --- a/samples/common-sample/build.gradle +++ b/samples/common-sample/build.gradle.kts @@ -14,18 +14,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import groovy.lang.Closure -apply from: '../../utils.gradle' - -setupMultiplatformLibrary(project, false) -setupAllTargetsWithDefaultSourceSets(project, false) // FIXME Js excluded here +plugins{ + id("org.jetbrains.kotlin.multiplatform") +} +apply(from = "../../utils.gradle") +val setupMultiplatformLibrary: Closure by ext +setupMultiplatformLibrary(project, false, false) // TODO extract JsPlugin from buildSrc to be used in other modules kotlin { sourceSets { - commonMain { + val commonMain by getting { dependencies { - implementation libs.kotlinx.atomicfu + implementation(libs.kotlinx.atomicfu) } } } diff --git a/samples/common/sample/build.gradle b/samples/common/sample/build.gradle.kts similarity index 65% rename from samples/common/sample/build.gradle rename to samples/common/sample/build.gradle.kts index 0fab10b..40266e3 100644 --- a/samples/common/sample/build.gradle +++ b/samples/common/sample/build.gradle.kts @@ -14,19 +14,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import groovy.lang.Closure -apply from: '../../../utils.gradle' +plugins{ + id("org.jetbrains.kotlin.multiplatform") +} -setupMultiplatformLibrary(project, false) -setupAllTargetsWithDefaultSourceSets(project, false) // FIXME Js excluded here +apply(from = "../../../utils.gradle") +val setupMultiplatformLibrary: Closure by ext +setupMultiplatformLibrary(project, false, false) // TODO extract JsPlugin from buildSrc to be used in other modules kotlin { sourceSets { - commonMain { + val commonMain by getting { dependencies { - implementation libs.kotlinx.atomicfu + implementation(libs.kotlinx.atomicfu) } } } -} - +} \ No newline at end of file diff --git a/samples/sample/build.gradle b/samples/sample/build.gradle deleted file mode 100644 index 5ff51c5..0000000 --- a/samples/sample/build.gradle +++ /dev/null @@ -1,51 +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. - */ - -apply from: '../../utils.gradle' - -setupMultiplatformLibrary(project, false) -setupAllTargetsWithDefaultSourceSets(project, false) // FIXME Js excluded here - -apply plugin: "com.careem.mockingbird" - -kotlin { - sourceSets { - commonMain { - dependencies { - implementation project(":common-sample") - implementation project(":common:sample") - implementation "com.careem.mockingbird:mockingbird" - implementation libs.touchlab.stately.isolate - } - } - } -} - -mockingBird { - generateMocksFor = [ - 'com.careem.mockingbird.sample.JavaTypes', - 'com.careem.mockingbird.sample.InterfaceWithGenerics', - 'com.careem.mockingbird.sample.PippoSample', - 'com.careem.mockingbird.sample.Mock1', - 'com.careem.mockingbird.sample.MockWithExternalDependencies', - 'com.careem.mockingbird.common.sample.ExternalContract', - 'com.careem.mockingbird.sample.OuterInterface', - 'com.careem.mockingbird.sample.MultipleGetterProperties', - 'com.careem.mockingbird.common.sample.ExternalDep' - ] -} - diff --git a/samples/sample/build.gradle.kts b/samples/sample/build.gradle.kts new file mode 100644 index 0000000..c05df9e --- /dev/null +++ b/samples/sample/build.gradle.kts @@ -0,0 +1,55 @@ +/** + * + * 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. + */ +import groovy.lang.Closure + +plugins{ + id("org.jetbrains.kotlin.multiplatform") +} + +apply(from = "../../utils.gradle") +val setupMultiplatformLibrary: Closure by ext +setupMultiplatformLibrary(project, false, false) // TODO extract JsPlugin from buildSrc to be used in other modules + +apply(plugin = "com.careem.mockingbird") + +kotlin { + sourceSets { + val commonMain by getting { + dependencies { + implementation(project(":common-sample")) + implementation(project(":common:sample")) + implementation("com.careem.mockingbird:mockingbird") + implementation(libs.touchlab.stately.isolate) + } + } + } +} + +configure { + generateMocksFor = listOf( + "com.careem.mockingbird.sample.JavaTypes", + "com.careem.mockingbird.sample.InterfaceWithGenerics", + "com.careem.mockingbird.sample.PippoSample", + "com.careem.mockingbird.sample.Mock1", + "com.careem.mockingbird.sample.MockWithExternalDependencies", + "com.careem.mockingbird.common.sample.ExternalContract", + "com.careem.mockingbird.sample.OuterInterface", + "com.careem.mockingbird.sample.MultipleGetterProperties", + "com.careem.mockingbird.common.sample.ExternalDep" + ) +} + diff --git a/utils.gradle b/utils.gradle index b705c8c..79743f7 100644 --- a/utils.gradle +++ b/utils.gradle @@ -14,8 +14,7 @@ * limitations under the License. */ -void setupMultiplatformLibrary(Project project, Boolean shouldPublish = true) { - project.apply plugin: 'org.jetbrains.kotlin.multiplatform' +void setupMultiplatformLibrary(Project project, Boolean shouldPublish = true, Boolean includeJs = true) { if (shouldPublish) { project.apply from: '../publishing.gradle' project.group = GROUP @@ -33,12 +32,14 @@ void setupMultiplatformLibrary(Project project, Boolean shouldPublish = true) { } } } + + setupAllTargetsWithDefaultSourceSets(project, includeJs) } -void setupAllTargetsWithDefaultSourceSets(Project project, Boolean includeJs = true) { +private void setupAllTargetsWithDefaultSourceSets(Project project, Boolean includeJs = true) { setupIosTargets(project) setupJvmTarget(project) - if(includeJs){ + if (includeJs) { setupJsTarget(project) } @@ -50,7 +51,7 @@ void setupAllTargetsWithDefaultSourceSets(Project project, Boolean includeJs = t jvmMain.dependsOn jvmJsCommonMain jvmTest.dependsOn jvmJsCommonTest - if(includeJs){ + if (includeJs) { jsMain.dependsOn jvmJsCommonMain jsTest.dependsOn jvmJsCommonTest } @@ -76,15 +77,9 @@ private void setupIosTargets(Project project) { private void setupJvmTarget(Project project) { project.kotlin { - targets.fromPreset(presets.jvm, 'jvm') + jvm() sourceSets { - jvmMain { - dependencies { - - } - } - jvmTest { dependencies { implementation libs.junit.junit @@ -98,6 +93,5 @@ private void setupJsTarget(Project project) { project.apply plugin: JsPlugin } -ext.setupMultiplatformLibrary = { Project project, Boolean shouldPublish -> setupMultiplatformLibrary(project, shouldPublish) } -ext.setupAllTargetsWithDefaultSourceSets = { Project project, Boolean includeJs -> setupAllTargetsWithDefaultSourceSets(project, includeJs) } +ext.setupMultiplatformLibrary = { Project project, Boolean shouldPublish, Boolean includeJs -> setupMultiplatformLibrary(project, shouldPublish, includeJs) }