-
Notifications
You must be signed in to change notification settings - Fork 308
/
build.gradle.kts
192 lines (177 loc) · 7.39 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeFeatureFlag
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
buildscript {
repositories {
// maven { setUrl("https://maven.aliyun.com/repository/public") } // central、jcenter
// maven { setUrl("https://maven.aliyun.com/repository/google") } // google
// maven { setUrl("https://repo.huaweicloud.com/repository/maven/") } // central、google、jcenter
// maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
gradlePluginPortal()
mavenCentral()
google()
}
dependencies {
classpath(libs.gradlePlugin.android)
classpath(libs.gradlePlugin.androidxNavigationSafeArgs)
classpath(libs.gradlePlugin.buildkonfig)
classpath(libs.gradlePlugin.jetbrainsCompose)
classpath(libs.gradlePlugin.kotlin)
classpath(libs.gradlePlugin.kotlinSerialization)
classpath(libs.gradlePlugin.kotlinComposeCompiler)
classpath(libs.gradlePlugin.kotlinxAtomicfu)
classpath(libs.gradlePlugin.kotlinxCover)
classpath(libs.gradlePlugin.mavenPublish)
}
}
allprojects {
repositories {
// maven { setUrl("https://maven.aliyun.com/repository/public") } // central、jcenter
// maven { setUrl("https://maven.aliyun.com/repository/google") } // google
// maven { setUrl("https://repo.huaweicloud.com/repository/maven/") } // central、google、jcenter
mavenCentral()
google()
maven { setUrl("https://www.jitpack.io") }
// maven { setUrl("https://s01.oss.sonatype.org/content/repositories/snapshots") }
// mavenLocal()
}
}
tasks.register("cleanRootBuild", Delete::class) {
delete(rootProject.project.layout.buildDirectory.get().asFile.absolutePath)
}
allprojects {
kotlinDependenciesConfig()
jvmTargetConfig()
composeConfig()
publishConfig()
applyOkioJsTestWorkaround()
androidTestConfig()
}
// TODO jetbrains-compose bug https://youtrack.jetbrains.com/issue/CMP-5831
allprojects {
configurations.all {
resolutionStrategy.eachDependency {
if (requested.group == "org.jetbrains.kotlinx" && requested.name == "atomicfu") {
useVersion(libs.versions.kotlinx.atomicfu.get())
}
}
}
}
fun Project.kotlinDependenciesConfig() {
dependencies {
modules {
module("org.jetbrains.kotlin:kotlin-stdlib-jdk7") {
replacedBy("org.jetbrains.kotlin:kotlin-stdlib")
}
module("org.jetbrains.kotlin:kotlin-stdlib-jdk8") {
replacedBy("org.jetbrains.kotlin:kotlin-stdlib")
}
}
}
}
fun Project.jvmTargetConfig() {
// Target JVM 8.
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
options.compilerArgs = options.compilerArgs + "-Xlint:-options"
}
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions.jvmTarget = JvmTarget.JVM_1_8
}
}
fun Project.composeConfig() {
plugins.withId("org.jetbrains.kotlin.plugin.compose") {
extensions.configure<ComposeCompilerGradlePluginExtension> {
featureFlags.addAll(
ComposeFeatureFlag.OptimizeNonSkippingGroups
)
stabilityConfigurationFile = rootDir.resolve("sketch-core/compose_compiler_config.conf")
/**
* Run the `./gradlew clean :sketch-compose:assembleRelease -PcomposeCompilerReports=true` command to generate a report,
* which is located in the `project/module/build/compose_compiler` directory.
*
* Interpretation of the report: https://developer.android.com/jetpack/compose/performance/stability/diagnose#kotlin
*/
if (project.findProperty("composeCompilerReports") == "true") {
val outputDir = layout.buildDirectory.dir("compose_compiler").get().asFile
metricsDestination = outputDir
reportsDestination = outputDir
}
}
}
}
fun Project.publishConfig() {
if (
// && hasProperty("mavenCentralUsername") // configured in the ~/.gradle/gradle.properties file
// && hasProperty("mavenCentralPassword") // configured in the ~/.gradle/gradle.properties file
hasProperty("versionName") // configured in the rootProject/gradle.properties file
&& hasProperty("GROUP") // configured in the rootProject/gradle.properties file
&& hasProperty("POM_ARTIFACT_ID") // configured in the project/gradle.properties file
) {
apply { plugin("com.vanniktech.maven.publish") }
configure<com.vanniktech.maven.publish.MavenPublishBaseExtension> {
version = property("versionName").toString()
if (hasProperty("signing.keyId") // configured in the ~/.gradle/gradle.properties file
&& hasProperty("signing.password") // configured in the ~/.gradle/gradle.properties file
&& hasProperty("signing.secretKeyRingFile") // configured in the ~/.gradle/gradle.properties file
) {
signAllPublications()
}
}
}
}
// https://github.com/square/okio/issues/1163
fun Project.applyOkioJsTestWorkaround() {
if (":sample" in displayName) {
// The polyfills cause issues with the sample.
return
}
plugins.withId("org.jetbrains.kotlin.multiplatform") {
val applyNodePolyfillPlugin by lazy {
tasks.register("applyNodePolyfillPlugin") {
val applyPluginFile = projectDir
.resolve("webpack.config.d/applyNodePolyfillPlugin.js")
onlyIf {
!applyPluginFile.exists()
}
doLast {
applyPluginFile.parentFile.mkdirs()
applyPluginFile.writeText(
"""
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
config.plugins.push(new NodePolyfillPlugin());
""".trimIndent(),
)
}
}
}
extensions.configure<KotlinMultiplatformExtension> {
sourceSets {
targets.configureEach {
compilations.configureEach {
if (platformType == KotlinPlatformType.js && name == "test") {
tasks
.getByName(compileKotlinTaskName)
.dependsOn(applyNodePolyfillPlugin)
dependencies {
implementation(devNpm("node-polyfill-webpack-plugin", "^2.0.1"))
}
}
}
}
}
}
}
}
fun Project.androidTestConfig() {
// Uninstall test APKs after running instrumentation tests.
tasks.configureEach {
if (name == "connectedDebugAndroidTest") {
finalizedBy("uninstallDebugAndroidTest")
}
}
}