Skip to content

Commit 51bff0d

Browse files
committed
chore: migrate build configuration to build-logic module.
Signed-off-by: 5peak2me <[email protected]>
1 parent ba9664c commit 51bff0d

File tree

13 files changed

+226
-163
lines changed

13 files changed

+226
-163
lines changed

build-logic/convention/build.gradle.kts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,25 @@ repositories {
1212
dependencies {
1313
implementation(libs.kotlin.gradle.plugin)
1414
implementation(libs.android.gradle.plugin)
15+
compileOnly(libs.compose.gradle.plugin)
1516
implementation(libs.dokka.plugin)
1617
implementation(libs.org.jacoco.core)
1718
implementation(libs.gradle.maven.publish.plugin)
18-
1919
}
2020

2121
gradlePlugin {
2222
plugins {
2323
register("publishingConventionPlugin") {
24-
id = "android.maps.compose.PublishingConventionPlugin"
24+
id = "android.maps.compose.publish"
2525
implementationClass = "PublishingConventionPlugin"
2626
}
27+
register("androidLibraryConventionPlugin") {
28+
id = "android.maps.compose.library"
29+
implementationClass = "AndroidLibraryConventionPlugin"
30+
}
31+
register("androidApplicationConventionPlugin") {
32+
id = "android.maps.compose.application"
33+
implementationClass = "AndroidApplicationConventionPlugin"
34+
}
2735
}
2836
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import com.android.build.api.dsl.ApplicationExtension
2+
import internal.configureAndroidCompose
3+
import internal.configureKotlinAndroid
4+
import org.gradle.api.Plugin
5+
import org.gradle.api.Project
6+
import org.gradle.kotlin.dsl.apply
7+
import org.gradle.kotlin.dsl.configure
8+
9+
class AndroidApplicationConventionPlugin : Plugin<Project> {
10+
override fun apply(target: Project) {
11+
with(target) {
12+
apply(plugin = "com.android.application")
13+
apply(plugin = "org.jetbrains.kotlin.android")
14+
15+
extensions.configure<ApplicationExtension> {
16+
configureKotlinAndroid(this, isLibrary = false)
17+
defaultConfig.targetSdk = 36
18+
defaultConfig.testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
19+
testOptions.animationsDisabled = true
20+
configureAndroidCompose(this)
21+
}
22+
}
23+
}
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import com.android.build.api.dsl.LibraryExtension
2+
import internal.configureAndroidCompose
3+
import internal.configureKotlinAndroid
4+
import org.gradle.api.Plugin
5+
import org.gradle.api.Project
6+
import org.gradle.kotlin.dsl.apply
7+
import org.gradle.kotlin.dsl.configure
8+
9+
class AndroidLibraryConventionPlugin : Plugin<Project> {
10+
override fun apply(target: Project) {
11+
with(target) {
12+
apply(plugin = "com.android.library")
13+
apply(plugin = "org.jetbrains.kotlin.android")
14+
15+
extensions.configure<LibraryExtension> {
16+
configureKotlinAndroid(this)
17+
testOptions.targetSdk = 36
18+
lint.targetSdk = 36
19+
defaultConfig.testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
20+
testOptions.animationsDisabled = true
21+
22+
configureAndroidCompose(this)
23+
}
24+
}
25+
}
26+
}

build-logic/convention/src/main/kotlin/PublishingConventionPlugin.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class PublishingConventionPlugin : Plugin<Project> {
2828
private fun Project.configureJacoco() {
2929
configure<JacocoPluginExtension> {
3030
toolVersion = "0.8.7"
31-
3231
}
3332

3433
tasks.withType<Test>().configureEach {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package internal
2+
3+
import com.android.build.api.dsl.CommonExtension
4+
import org.gradle.api.Project
5+
import org.gradle.api.provider.Provider
6+
import org.gradle.kotlin.dsl.apply
7+
import org.gradle.kotlin.dsl.configure
8+
import org.gradle.kotlin.dsl.dependencies
9+
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension
10+
11+
/**
12+
* Configure Compose-specific options
13+
*/
14+
internal fun Project.configureAndroidCompose(
15+
commonExtension: CommonExtension<*, *, *, *, *, *>,
16+
) {
17+
apply(plugin = "org.jetbrains.kotlin.plugin.compose")
18+
19+
commonExtension.apply {
20+
buildFeatures {
21+
compose = true
22+
}
23+
24+
dependencies {
25+
val bom = libs.findLibrary("androidx-compose-bom").get()
26+
"implementation"(platform(bom))
27+
"androidTestImplementation"(platform(bom))
28+
"implementation"(libs.findLibrary("androidx-compose-ui-preview-tooling").get())
29+
"debugImplementation"(libs.findLibrary("androidx-compose-ui-tooling").get())
30+
}
31+
}
32+
33+
// extensions.configure<ComposeCompilerGradlePluginExtension> {
34+
// fun Provider<String>.onlyIfTrue() = flatMap { provider { it.takeIf(String::toBoolean) } }
35+
// fun Provider<*>.relativeToRootProject(dir: String) = map {
36+
// isolated.rootProject.projectDirectory
37+
// .dir("build")
38+
// .dir(projectDir.toRelativeString(rootDir))
39+
// }.map { it.dir(dir) }
40+
//
41+
// project.providers.gradleProperty("composeCompilerMetrics").onlyIfTrue()
42+
// .relativeToRootProject("compose-metrics")
43+
// .let(metricsDestination::set)
44+
//
45+
// project.providers.gradleProperty("composeCompilerReports").onlyIfTrue()
46+
// .relativeToRootProject("compose-reports")
47+
// .let(reportsDestination::set)
48+
//
49+
// stabilityConfigurationFiles
50+
// .add(isolated.rootProject.projectDirectory.file("compose_compiler_config.conf"))
51+
// }
52+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package internal
2+
3+
import com.android.build.api.dsl.CommonExtension
4+
import org.gradle.api.JavaVersion
5+
import org.gradle.api.Project
6+
import org.gradle.api.plugins.JavaPluginExtension
7+
import org.gradle.kotlin.dsl.assign
8+
import org.gradle.kotlin.dsl.configure
9+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
10+
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
11+
import org.jetbrains.kotlin.gradle.dsl.KotlinBaseExtension
12+
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
13+
14+
/**
15+
* Configure base Kotlin with Android options
16+
*/
17+
internal fun Project.configureKotlinAndroid(
18+
commonExtension: CommonExtension<*, *, *, *, *, *>,
19+
isLibrary: Boolean = true
20+
) {
21+
commonExtension.apply {
22+
lint {
23+
sarifOutput = layout.buildDirectory.file("reports/lint-results.sarif").get().asFile
24+
}
25+
26+
compileSdk = 36
27+
28+
defaultConfig {
29+
minSdk = 21
30+
}
31+
32+
compileOptions {
33+
sourceCompatibility = JavaVersion.VERSION_1_8
34+
targetCompatibility = JavaVersion.VERSION_1_8
35+
}
36+
37+
buildFeatures {
38+
buildConfig = false
39+
}
40+
}
41+
42+
configureKotlin<KotlinAndroidProjectExtension>(isLibrary)
43+
}
44+
45+
/**
46+
* Configure base Kotlin options for JVM (non-Android)
47+
*/
48+
internal fun Project.configureKotlinJvm() {
49+
extensions.configure<JavaPluginExtension> {
50+
targetCompatibility = JavaVersion.VERSION_1_8
51+
}
52+
53+
configureKotlin<KotlinJvmProjectExtension>()
54+
}
55+
56+
/**
57+
* Configure base Kotlin options
58+
*/
59+
private inline fun <reified T : KotlinBaseExtension> Project.configureKotlin(isLibrary: Boolean = true) = configure<T> {
60+
// Treat all Kotlin warnings as errors (disabled by default)
61+
// Override by setting warningsAsErrors=true in your ~/.gradle/gradle.properties
62+
val warningsAsErrors = providers.gradleProperty("warningsAsErrors").map {
63+
it.toBoolean()
64+
}.orElse(false)
65+
when (this) {
66+
is KotlinAndroidProjectExtension -> compilerOptions
67+
is KotlinJvmProjectExtension -> compilerOptions
68+
else -> TODO("Unsupported project extension $this ${T::class}")
69+
}.apply {
70+
jvmTarget = JvmTarget.JVM_1_8
71+
allWarningsAsErrors = warningsAsErrors
72+
freeCompilerArgs.add(
73+
"-Xopt-in=kotlin.RequiresOptIn"
74+
)
75+
if (isLibrary) {
76+
freeCompilerArgs.add(
77+
"-Xexplicit-api=strict"
78+
)
79+
}
80+
freeCompilerArgs.add(
81+
// Enable experimental coroutines APIs, including Flow
82+
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
83+
)
84+
}
85+
}
86+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package internal
2+
3+
import org.gradle.api.Project
4+
import org.gradle.api.artifacts.VersionCatalog
5+
import org.gradle.api.artifacts.VersionCatalogsExtension
6+
import org.gradle.kotlin.dsl.getByType
7+
8+
val Project.libs
9+
get(): VersionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
10+

build.gradle.kts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
1-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2-
buildscript {
3-
val kotlinVersion by extra(libs.versions.kotlin.get())
4-
val androidxTestVersion by extra(libs.versions.androidxtest.get())
5-
repositories {
6-
google()
7-
mavenCentral()
8-
}
9-
dependencies {
10-
classpath(libs.android.gradle.plugin)
11-
classpath(libs.maps.secrets.plugin)
12-
classpath(libs.kotlin.gradle.plugin)
13-
classpath(libs.dokka.plugin)
14-
classpath(libs.jacoco.android.plugin)
15-
}
16-
}
17-
181
plugins {
192
alias(libs.plugins.dokka) apply true
203
alias(libs.plugins.compose.compiler) apply false
214
id("com.autonomousapps.dependency-analysis") version "2.0.0"
225
alias(libs.plugins.android.application) apply false
6+
alias(libs.plugins.android.library) apply false
237
alias(libs.plugins.kotlin.android) apply false
24-
8+
alias(libs.plugins.maps.secrets.gradle.plugin) apply false
9+
alias(libs.plugins.jacoco.android) apply false
2510
}
2611

2712
val projectArtifactId by extra { project: Project ->

gradle/libs.versions.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,14 @@ androidx-test-rules = { module = "androidx.test:rules", version.ref = "androidCo
4343
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidxtest" }
4444
dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
4545
gradle-maven-publish-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "gradleMavenPublishPlugin" }
46-
jacoco-android-plugin = { module = "com.mxalbert.gradle:jacoco-android", version.ref = "jacoco-plugin", version.require = "0.2.1" }
46+
compose-gradle-plugin = { module = "org.jetbrains.kotlin:compose-compiler-gradle-plugin", version.ref = "kotlin" }
4747
kotlin = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk7", version.ref = "kotlin" }
48-
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
48+
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version = "2.2.0" }
4949
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinxCoroutines" }
5050
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinxCoroutines" }
5151
leakcanary-android = { module = "com.squareup.leakcanary:leakcanary-android", version.ref = "leakcanaryAndroid" }
5252
maps-ktx-std = { module = "com.google.maps.android:maps-ktx", version.ref = "mapsktx" }
5353
maps-ktx-utils = { module = "com.google.maps.android:maps-utils-ktx", version.ref = "mapsktx" }
54-
maps-secrets-plugin = { module = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin", version.ref = "mapsecrets" }
5554
org-jacoco-core = { module = "org.jacoco:org.jacoco.core", version.ref = "org-jacoco-core" }
5655
test-junit = { module = "junit:junit", version.ref = "junit" }
5756
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
@@ -62,7 +61,10 @@ truth = { module = "com.google.truth:truth", version.ref = "truth" }
6261

6362
[plugins]
6463
android-application = { id = "com.android.application", version.ref = "agp" }
64+
android-library = { id = "com.android.library", version.ref = "agp" }
6565
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
6666
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
6767
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
6868
screenshot = { id = "com.android.compose.screenshot", version.ref = "screenshot"}
69+
maps-secrets-gradle-plugin = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version.ref = "mapsecrets" }
70+
jacoco-android = { id = "com.mxalbert.gradle.jacoco-android", version.ref = "jacoco-plugin" }

maps-app/build.gradle.kts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
22

33
plugins {
4-
id("com.android.application")
5-
id("kotlin-android")
6-
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
7-
alias(libs.plugins.compose.compiler)
4+
id("android.maps.compose.application")
5+
alias(libs.plugins.maps.secrets.gradle.plugin)
86
alias(libs.plugins.screenshot)
97
}
108

119
android {
12-
lint {
13-
sarifOutput = layout.buildDirectory.file("reports/lint-results.sarif").get().asFile
14-
}
15-
1610
buildTypes {
1711
getByName("debug") {
1812
enableUnitTestCoverage = true
@@ -25,34 +19,15 @@ android {
2519
}
2620

2721
namespace = "com.google.maps.android.compose"
28-
compileSdk = 36
2922

3023
defaultConfig {
31-
minSdk = 21
32-
targetSdk = 36
3324
versionCode = 1
3425
versionName = "1.0"
35-
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3626
}
3727

38-
compileOptions {
39-
sourceCompatibility = JavaVersion.VERSION_1_8
40-
targetCompatibility = JavaVersion.VERSION_1_8
41-
}
4228

4329
buildFeatures {
4430
buildConfig = true
45-
compose = true
46-
}
47-
48-
49-
kotlin {
50-
compilerOptions {
51-
jvmTarget.set(JvmTarget.JVM_1_8)
52-
freeCompilerArgs.addAll(
53-
"-opt-in=kotlin.RequiresOptIn"
54-
)
55-
}
5631
}
5732

5833
experimentalProperties["android.experimental.enableScreenshotTest"] = true
@@ -65,7 +40,6 @@ android {
6540
}
6641

6742
dependencies {
68-
implementation(platform(libs.androidx.compose.bom))
6943
implementation(libs.androidx.compose.activity)
7044
implementation(libs.androidx.compose.foundation)
7145
implementation(libs.androidx.compose.material)
@@ -79,7 +53,6 @@ dependencies {
7953
debugImplementation(libs.androidx.compose.ui.tooling)
8054
debugImplementation(libs.leakcanary.android)
8155

82-
androidTestImplementation(platform(libs.androidx.compose.bom))
8356
androidTestImplementation(libs.androidx.test.core)
8457
androidTestImplementation(libs.androidx.test.rules)
8558
androidTestImplementation(libs.androidx.test.runner)

0 commit comments

Comments
 (0)