Skip to content

Commit b4e2da2

Browse files
[ENG-42] General build scripts clean up (#157)
Cleaning up build scripts
1 parent 22f556b commit b4e2da2

File tree

10 files changed

+83
-16
lines changed

10 files changed

+83
-16
lines changed

build.gradle.kts

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
* limitations under the License.
1616
*/
1717
plugins {
18-
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
18+
alias(libs.plugins.kotlin.ksp) apply false
19+
alias(libs.plugins.kotlin.multiplatform) apply false
20+
alias(libs.plugins.gmazzo.buildconfig) apply false
21+
alias(libs.plugins.nexus.publish)
1922
id("maven-publish")
2023
signing
2124
}

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

mockingbird-compiler/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
plugins {
1919
`kotlin-dsl`
20-
id("com.github.gmazzo.buildconfig") version libs.versions.buildconfig.get()
20+
alias(libs.plugins.gmazzo.buildconfig)
2121
id("maven-publish")
2222
signing
2323
}

samples/build.gradle.kts

+4-10
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,10 @@
1515
* limitations under the License.
1616
*/
1717

18-
buildscript {
19-
repositories {
20-
google()
21-
mavenCentral()
22-
}
23-
24-
dependencies {
25-
classpath(libs.kotlin.gradle)
26-
classpath("com.careem.mockingbird:mockingbird-compiler")
27-
}
18+
plugins {
19+
alias(libs.plugins.kotlin.ksp) apply false
20+
alias(libs.plugins.kotlin.multiplatform) apply false
21+
id("com.careem.mockingbird") apply false
2822
}
2923

3024
allprojects {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

samples/kspsample/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717

1818
plugins {
19-
alias(libs.plugins.kotlin.ksp)
2019
alias(libs.plugins.kotlin.multiplatform)
20+
alias(libs.plugins.kotlin.ksp)
2121
id("com.careem.mockingbird")
2222
}
2323

samples/properties.gradle

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright Careem, an Uber Technologies Inc. company
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Copies main project Gradle properties to sample project. Can't use buildSrc because settings.gradle
18+
// must access these properties.
19+
20+
List<String> propertiesFiles = [
21+
"../gradle.properties",
22+
"../local.properties",
23+
]
24+
25+
propertiesFiles.each { fileName ->
26+
File file = file(fileName)
27+
if (file.exists()) {
28+
Properties properties = new Properties()
29+
file.withInputStream { properties.load(it) }
30+
31+
int moduleNameStartIndex = fileName.indexOf('/') + 1
32+
int moduleNameEndIndex = fileName.lastIndexOf('/')
33+
String namespace
34+
if (moduleNameStartIndex < moduleNameEndIndex) {
35+
namespace = fileName.substring(moduleNameStartIndex, moduleNameEndIndex)
36+
.replace('/', '.')
37+
} else {
38+
namespace = null
39+
}
40+
41+
properties.each { key, value ->
42+
String namespacedKey
43+
if (namespace == null) {
44+
namespacedKey = key
45+
} else {
46+
namespacedKey = "$namespace.$key"
47+
}
48+
try {
49+
properties.set(namespacedKey, value)
50+
} catch (MissingMethodException ignored) {
51+
// We are in a pluginManagement block that can't set properties, so set an extra instead:
52+
ext.set(namespacedKey, value)
53+
}
54+
}
55+
}
56+
57+
}

samples/sample/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import groovy.lang.Closure
1818

1919
plugins{
20-
id("org.jetbrains.kotlin.multiplatform")
20+
alias(libs.plugins.kotlin.multiplatform)
2121
id("com.careem.mockingbird")
2222
}
2323

samples/settings.gradle.kts

+11
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,21 @@
1515
* limitations under the License.
1616
*/
1717
pluginManagement {
18+
apply(from = "properties.gradle")
1819
repositories {
1920
gradlePluginPortal()
2021
mavenCentral()
2122
google()
23+
mavenLocal()
24+
}
25+
26+
resolutionStrategy {
27+
val publishVersion = extra["VERSION"] as String
28+
eachPlugin {
29+
if (requested.id.id == "com.careem.mockingbird") {
30+
useVersion(publishVersion)
31+
}
32+
}
2233
}
2334
}
2435

versions.toml

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ kotlinxMetadata = "0.7.0"
1313
mockk = "1.13.5"
1414
buildconfig = "4.1.2"
1515
coroutines = "1.7.3"
16+
nexus-publish = "1.1.0"
1617

1718
[libraries]
1819
jacoco-jacoco = { module = "org.jacoco:org.jacoco.core", version.ref = "jacoco" }
@@ -40,6 +41,7 @@ kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.
4041
mockk-mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
4142

4243
[plugins]
44+
nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexus-publish" }
4345
gmazzo-buildconfig = { id = "com.github.gmazzo.buildconfig", version.ref = "buildconfig" }
4446
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
4547
kotlin-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }

0 commit comments

Comments
 (0)