Skip to content

Commit c09c404

Browse files
null2264AntsyLich
andcommitted
refactor: Rework buildSrc
Co-authored-by: AntsyLich <[email protected]>
1 parent b201e41 commit c09c404

19 files changed

+218
-86
lines changed

app/build.gradle.kts

+3-19
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import java.time.format.DateTimeFormatter
77
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
88

99
plugins {
10-
alias(androidx.plugins.application)
11-
alias(kotlinx.plugins.android)
12-
alias(kotlinx.plugins.compose.compiler)
10+
id("yokai.android.application")
11+
id("yokai.android.application.compose")
1312
alias(kotlinx.plugins.serialization)
1413
alias(kotlinx.plugins.parcelize)
1514
alias(libs.plugins.aboutlibraries)
@@ -122,7 +121,6 @@ android {
122121

123122
buildFeatures {
124123
viewBinding = true
125-
compose = true
126124
// If you're here because there's not BuildConfig, build the app first, it'll generate it for you
127125
buildConfig = true
128126

@@ -284,33 +282,19 @@ tasks {
284282
// "-opt-in=kotlin.Experimental",
285283
"-opt-in=kotlin.RequiresOptIn",
286284
"-opt-in=kotlin.ExperimentalStdlibApi",
285+
"-opt-in=coil3.annotation.ExperimentalCoilApi",
287286
"-opt-in=androidx.compose.foundation.layout.ExperimentalLayoutApi",
288287
"-opt-in=androidx.compose.material3.ExperimentalMaterial3Api",
289288
"-opt-in=androidx.compose.ui.ExperimentalComposeUiApi",
290289
"-opt-in=androidx.compose.foundation.ExperimentalFoundationApi",
291290
"-opt-in=androidx.compose.animation.ExperimentalAnimationApi",
292-
// "-opt-in=androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi",
293-
"-opt-in=coil3.annotation.ExperimentalCoilApi",
294291
// "-opt-in=com.google.accompanist.permissions.ExperimentalPermissionsApi",
295292
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
296293
"-opt-in=kotlinx.coroutines.FlowPreview",
297294
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
298295
"-opt-in=kotlinx.coroutines.InternalCoroutinesApi",
299296
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
300297
)
301-
302-
if (project.findProperty("tachiyomi.enableComposeCompilerMetrics") == "true") {
303-
compilerOptions.freeCompilerArgs.addAll(
304-
"-P",
305-
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" +
306-
(project.layout.buildDirectory.asFile.orNull?.absolutePath ?: "/tmp/yokai") + "/compose_metrics",
307-
)
308-
compilerOptions.freeCompilerArgs.addAll(
309-
"-P",
310-
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" +
311-
(project.layout.buildDirectory.asFile.orNull?.absolutePath ?: "/tmp/yokai") + "/compose_metrics",
312-
)
313-
}
314298
}
315299

316300
// Duplicating Hebrew string assets due to some locale code issues on different devices

build.gradle.kts

-46
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ import java.util.*
88
plugins {
99
alias(libs.plugins.kotlinter)
1010
alias(libs.plugins.gradle.versions)
11-
alias(androidx.plugins.application) apply false
12-
alias(androidx.plugins.library) apply false
13-
alias(kotlinx.plugins.android) apply false
14-
alias(kotlinx.plugins.compose.compiler) apply false
15-
alias(kotlinx.plugins.multiplatform) apply false
16-
alias(kotlinx.plugins.parcelize) apply false
1711
alias(kotlinx.plugins.serialization) apply false
1812
alias(libs.plugins.aboutlibraries) apply false
1913
alias(libs.plugins.firebase.crashlytics) apply false
@@ -22,46 +16,6 @@ plugins {
2216
alias(libs.plugins.sqldelight) apply false
2317
}
2418

25-
subprojects {
26-
tasks.withType<KotlinCompile> {
27-
compilerOptions {
28-
jvmTarget = JvmTarget.JVM_17
29-
}
30-
}
31-
32-
tasks.withType<Test> {
33-
useJUnitPlatform()
34-
testLogging {
35-
events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
36-
}
37-
}
38-
39-
plugins.withType<BasePlugin> {
40-
configure<BaseExtension> {
41-
compileSdkVersion(AndroidConfig.compileSdk)
42-
ndkVersion = AndroidConfig.ndk
43-
44-
defaultConfig {
45-
minSdk = AndroidConfig.minSdk
46-
targetSdk = AndroidConfig.targetSdk
47-
ndk {
48-
version = AndroidConfig.ndk
49-
}
50-
}
51-
52-
compileOptions {
53-
sourceCompatibility = JavaVersion.VERSION_17
54-
targetCompatibility = JavaVersion.VERSION_17
55-
isCoreLibraryDesugaringEnabled = true
56-
}
57-
58-
dependencies {
59-
add("coreLibraryDesugaring", libs.desugar)
60-
}
61-
}
62-
}
63-
}
64-
6519
tasks.named("dependencyUpdates", com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask::class.java).configure {
6620
rejectVersionIf {
6721
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { candidate.version.uppercase(Locale.ROOT).contains(it) }

buildSrc/build.gradle.kts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
plugins {
22
`kotlin-dsl`
33
}
4+
5+
dependencies {
6+
implementation(androidx.gradle)
7+
implementation(kotlinx.gradle)
8+
implementation(kotlinx.compose.compiler.gradle)
9+
implementation(gradleApi())
10+
11+
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
12+
implementation(files(androidx.javaClass.superclass.protectionDomain.codeSource.location))
13+
implementation(files(compose.javaClass.superclass.protectionDomain.codeSource.location))
14+
implementation(files(kotlinx.javaClass.superclass.protectionDomain.codeSource.location))
15+
}
16+
417
repositories {
18+
gradlePluginPortal()
519
mavenCentral()
6-
}
20+
google()
21+
}

buildSrc/settings.gradle.kts

+17
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1+
dependencyResolutionManagement {
2+
versionCatalogs {
3+
create("libs") {
4+
from(files("../gradle/libs.versions.toml"))
5+
}
6+
create("androidx") {
7+
from(files("../gradle/androidx.versions.toml"))
8+
}
9+
create("compose") {
10+
from(files("../gradle/compose.versions.toml"))
11+
}
12+
create("kotlinx") {
13+
from(files("../gradle/kotlinx.versions.toml"))
14+
}
15+
}
16+
}
17+
118
rootProject.name = "yokai-buildSrc"
+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import org.gradle.api.JavaVersion as GradleJavaVersion
2+
13
object AndroidConfig {
2-
const val compileSdk = 35
3-
const val minSdk = 23
4-
const val targetSdk = 35
5-
const val ndk = "27.2.12479018"
4+
const val COMPILE_SDK = 35
5+
const val MIN_SDK = 23
6+
const val TARGET_SDK = 35
7+
const val NDK = "27.2.12479018"
8+
val JavaVersion = GradleJavaVersion.VERSION_17
69
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import yokai.build.configureCompose
2+
3+
plugins {
4+
id("com.android.application")
5+
kotlin("android")
6+
}
7+
8+
android {
9+
configureCompose(this)
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import yokai.build.configureAndroid
2+
import yokai.build.configureTest
3+
4+
plugins {
5+
id("com.android.application")
6+
kotlin("android")
7+
}
8+
9+
android {
10+
defaultConfig {
11+
targetSdk = AndroidConfig.TARGET_SDK
12+
}
13+
configureAndroid(this)
14+
configureTest()
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import yokai.build.configureCompose
2+
3+
plugins {
4+
id("com.android.library")
5+
}
6+
7+
android {
8+
configureCompose(this)
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import yokai.build.configureAndroid
2+
import yokai.build.configureTest
3+
4+
plugins {
5+
id("com.android.library")
6+
}
7+
8+
android {
9+
configureAndroid(this)
10+
configureTest()
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,98 @@
11
package yokai.build
22

3+
import com.android.build.api.dsl.CommonExtension
4+
import org.gradle.accessors.dm.LibrariesForAndroidx
5+
import org.gradle.accessors.dm.LibrariesForCompose
6+
import org.gradle.accessors.dm.LibrariesForKotlinx
7+
import org.gradle.accessors.dm.LibrariesForLibs
38
import org.gradle.api.Project
9+
import org.gradle.api.tasks.testing.Test
10+
import org.gradle.api.tasks.testing.logging.TestLogEvent
11+
import org.gradle.kotlin.dsl.configure
12+
import org.gradle.kotlin.dsl.dependencies
13+
import org.gradle.kotlin.dsl.provideDelegate
14+
import org.gradle.kotlin.dsl.the
15+
import org.gradle.kotlin.dsl.withType
16+
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension
17+
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeFeatureFlag
18+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
419
import java.io.File
520

21+
val Project.androidx get() = the<LibrariesForAndroidx>()
22+
val Project.compose get() = the<LibrariesForCompose>()
23+
val Project.kotlinx get() = the<LibrariesForKotlinx>()
24+
val Project.libs get() = the<LibrariesForLibs>()
25+
626
val Project.generatedBuildDir: File get() = project.layout.buildDirectory.asFile.get().resolve("generated/yokai")
27+
28+
internal fun Project.configureAndroid(commonExtension: CommonExtension<*, *, *, *, *, *>) {
29+
commonExtension.apply {
30+
compileSdk = AndroidConfig.COMPILE_SDK
31+
defaultConfig {
32+
minSdk = AndroidConfig.MIN_SDK
33+
ndk {
34+
version = AndroidConfig.NDK
35+
}
36+
}
37+
compileOptions {
38+
sourceCompatibility = AndroidConfig.JavaVersion
39+
targetCompatibility = AndroidConfig.JavaVersion
40+
isCoreLibraryDesugaringEnabled = true
41+
}
42+
}
43+
tasks.withType<KotlinCompile>().configureEach {
44+
kotlinOptions {
45+
jvmTarget = AndroidConfig.JavaVersion.toString()
46+
// freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
47+
// freeCompilerArgs += "-Xcontext-receivers"
48+
// Treat all Kotlin warnings as errors (disabled by default)
49+
// Override by setting warningsAsErrors=true in your ~/.gradle/gradle.properties
50+
// val warningsAsErrors: String? by project
51+
// allWarningsAsErrors = warningsAsErrors.toBoolean()
52+
}
53+
}
54+
dependencies {
55+
"coreLibraryDesugaring"(libs.desugar)
56+
}
57+
}
58+
59+
internal fun Project.configureCompose(commonExtension: CommonExtension<*, *, *, *, *, *>) {
60+
pluginManager.apply(kotlinx.plugins.compose.compiler.get().pluginId)
61+
62+
commonExtension.apply {
63+
buildFeatures {
64+
compose = true
65+
}
66+
67+
dependencies {
68+
"implementation"(platform(compose.bom))
69+
}
70+
}
71+
72+
extensions.configure<ComposeCompilerGradlePluginExtension> {
73+
featureFlags.set(setOf(ComposeFeatureFlag.OptimizeNonSkippingGroups))
74+
75+
val enableMetrics = project.providers.gradleProperty("enableComposeCompilerMetrics").orNull.toBoolean()
76+
val enableReports = project.providers.gradleProperty("enableComposeCompilerReports").orNull.toBoolean()
77+
78+
val rootBuildDir = rootProject.layout.buildDirectory.asFile.get()
79+
val relativePath = projectDir.relativeTo(rootDir)
80+
81+
if (enableMetrics) {
82+
rootBuildDir.resolve("compose-metrics").resolve(relativePath).let(metricsDestination::set)
83+
}
84+
85+
if (enableReports) {
86+
rootBuildDir.resolve("compose-reports").resolve(relativePath).let(reportsDestination::set)
87+
}
88+
}
89+
}
90+
91+
internal fun Project.configureTest() {
92+
tasks.withType<Test> {
93+
useJUnitPlatform()
94+
testLogging {
95+
events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
96+
}
97+
}
98+
}

core/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22

33
plugins {
4-
alias(androidx.plugins.library)
5-
alias(kotlinx.plugins.multiplatform)
4+
id("yokai.android.library")
5+
kotlin("multiplatform")
66
alias(kotlinx.plugins.serialization)
77
}
88

data/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
2-
alias(kotlinx.plugins.multiplatform)
2+
id("yokai.android.library")
3+
kotlin("multiplatform")
34
alias(kotlinx.plugins.serialization)
4-
alias(androidx.plugins.library)
55
alias(libs.plugins.sqldelight)
66
}
77

domain/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
2-
alias(kotlinx.plugins.multiplatform)
2+
id("yokai.android.library")
3+
kotlin("multiplatform")
34
alias(kotlinx.plugins.serialization)
4-
alias(androidx.plugins.library)
55
}
66

77
kotlin {

gradle/androidx.versions.toml

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ agp = "8.7.3"
44
lifecycle = "2.8.7"
55

66
[libraries]
7+
gradle = { module = "com.android.tools.build:gradle", version.ref = "agp" }
8+
79
activity = { module = "androidx.activity:activity-ktx", version.ref = "activity" }
810
activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activity" }
911
annotation = { module = "androidx.annotation:annotation", version = "1.9.1" }

gradle/kotlinx.versions.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ serialization = "1.7.3"
44
xml_serialization = "0.90.3"
55

66
[libraries]
7+
gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
8+
compose-compiler-gradle = { module = "org.jetbrains.kotlin:compose-compiler-gradle-plugin", version.ref = "kotlin" }
9+
710
coroutines-bom = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-bom", version = "1.10.1" }
811
coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android" }
912
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core" }
@@ -26,4 +29,4 @@ android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
2629
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
2730
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
2831
serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
29-
parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
32+
parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize" }

i18n/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import yokai.build.generatedBuildDir
22
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
33

44
plugins {
5-
alias(kotlinx.plugins.multiplatform)
6-
alias(androidx.plugins.library)
5+
id("yokai.android.library")
6+
kotlin("multiplatform")
77
alias(libs.plugins.moko)
88
}
99

0 commit comments

Comments
 (0)