From d88e53fa0cd627a73e00b0f06c2b2cf3d389917a Mon Sep 17 00:00:00 2001 From: nian1 Date: Fri, 5 Jul 2024 17:14:24 +0800 Subject: [PATCH 1/3] Update .gitignore --- .gitignore | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index ae07f76..c6514dd 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,17 @@ misc.xml deploymentTargetDropDown.xml render.experimental.xml +# Xcode +**/build/ +xcuserdata +!src/**/build/ +*.xcodeproj/* +!*.xcodeproj/project.pbxproj +!*.xcodeproj/xcshareddata/ +!*.xcodeproj/project.xcworkspace/ +!*.xcworkspace/contents.xcworkspacedata +**/xcshareddata/WorkspaceSettings.xcsettings + # Fleet .fleet/ @@ -43,13 +54,3 @@ google-services.json # Signing configuration file keystore.properties - -**/build/ -xcuserdata -!src/**/build/ -*.xcodeproj/* -!*.xcodeproj/project.pbxproj -!*.xcodeproj/xcshareddata/ -!*.xcodeproj/project.xcworkspace/ -!*.xcworkspace/contents.xcworkspacedata -**/xcshareddata/WorkspaceSettings.xcsettings From e83677f299611a6499f6475ce29493121ac89f1d Mon Sep 17 00:00:00 2001 From: nian1 Date: Fri, 5 Jul 2024 17:48:49 +0800 Subject: [PATCH 2/3] Update targetSdk to 34 --- androidApp/src/main/AndroidManifest.xml | 2 ++ build-logic/convention/src/main/kotlin/Configuration.kt | 2 +- shared-compose/src/androidMain/AndroidManifest.xml | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/androidApp/src/main/AndroidManifest.xml b/androidApp/src/main/AndroidManifest.xml index 443f06a..eb6d56b 100644 --- a/androidApp/src/main/AndroidManifest.xml +++ b/androidApp/src/main/AndroidManifest.xml @@ -3,6 +3,8 @@ xmlns:tools="http://schemas.android.com/tools" android:installLocation="auto"> + + - From 6046b57af23cf66634cca365fc1efd53c2f50f25 Mon Sep 17 00:00:00 2001 From: nian1 Date: Fri, 5 Jul 2024 17:53:34 +0800 Subject: [PATCH 3/3] Update build config --- androidApp/build.gradle.kts | 1 - build-logic/convention/build.gradle.kts | 6 +- .../src/main/kotlin/BuildSupportPlugin.kt | 108 ++++++++++++++++++ build.gradle.kts | 39 +------ 4 files changed, 115 insertions(+), 39 deletions(-) create mode 100644 build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 0227146..60248ef 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -4,7 +4,6 @@ plugins { alias(libs.plugins.android.application) kotlin("android") alias(libs.plugins.compose.compiler) - id("com.jithub.build.logic") } android { diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index 6911b64..3e31d5f 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -35,8 +35,12 @@ dependencies { gradlePlugin { plugins { register("build-logic") { - id = "com.jithub.build.logic" + id = "com.jithub.build-logic" implementationClass = "BuildLogic" } + register("build-support") { + id = "com.jithub.build-support" + implementationClass = "BuildSupportPlugin" + } } } diff --git a/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt b/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt new file mode 100644 index 0000000..b4d4b64 --- /dev/null +++ b/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt @@ -0,0 +1,108 @@ +import org.gradle.api.Project +import org.gradle.api.tasks.compile.JavaCompile +import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.mpp.Framework +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile + +class BuildSupportPlugin : BasePlugin() { + + override fun apply(target: Project) { + log("apply target: ${target.displayName}") + + target.group = "com.jithub.build-support" + target.version = "0.1" + + target.configureCommonKotlin() + target.configureCommonCompose() + } + + // https://github.com/cashapp/redwood/blob/trunk/build-support/src/main/kotlin/app/cash/redwood/buildsupport/RedwoodBuildPlugin.kt + private fun Project.configureCommonKotlin() { + tasks.withType(KotlinCompile::class.java).configureEach { + compilerOptions { + // Treat all Kotlin warnings as errors (disabled by default) + allWarningsAsErrors.set(properties["warningsAsErrors"] as? Boolean ?: false) + + freeCompilerArgs.set( + freeCompilerArgs.getOrElse(emptyList()) + listOf( + // https://kotlinlang.org/docs/whatsnew13.html#progressive-mode + "-progressive", + // https://kotlinlang.org/docs/multiplatform-expect-actual.html#expected-and-actual-classes + "-Xexpect-actual-classes" + ) + ) + } + } + + tasks.withType(KotlinJvmCompile::class.java).configureEach { + compilerOptions { + freeCompilerArgs.set( + freeCompilerArgs.getOrElse(emptyList()) + listOf( + "-Xjvm-default=all" + ) + ) + jvmTarget.set(Versions.jvmTarget) + } + } + + // Kotlin requires the Java compatibility matches. + tasks.withType(JavaCompile::class.java).configureEach { + sourceCompatibility = Versions.javaVersion.toString() + targetCompatibility = Versions.javaVersion.toString() + } + + plugins.withId("org.jetbrains.kotlin.multiplatform") { + val kotlin = extensions.getByName("kotlin") as KotlinMultiplatformExtension + + // We set the JVM target (the bytecode version) above for all Kotlin-based Java bytecode + // compilations, but we also need to set the JDK API version for the Kotlin JVM targets to + // prevent linking against newer JDK APIs (the Android targets link against the android.jar). + kotlin.targets.withType(KotlinJvmTarget::class.java) { + compilations.configureEach { + compileTaskProvider.configure { + compilerOptions { + freeCompilerArgs.set( + freeCompilerArgs.getOrElse(emptyList()) + listOf( + "-Xjdk-release=${Versions.javaVersion}" + ) + ) + } + } + } + } + + kotlin.targets.withType(KotlinNativeTarget::class.java) { + binaries.withType(Framework::class.java) { + linkerOpts += "-lsqlite3" + } + } + } + } + + /** + * Force Android Compose UI and JetPack Compose UI usage to Compose compiler versions which are compatible + * with the project's Kotlin version. + */ + private fun Project.configureCommonCompose() { + tasks.withType().configureEach { + compilerOptions { + freeCompilerArgs.set( + freeCompilerArgs.getOrElse(emptyList()) + listOf( + // https://github.com/JetBrains/compose-multiplatform/issues/3421 + "-Xpartial-linkage=disable", + // https://github.com/JetBrains/compose-multiplatform/issues/3418 + "-Xklib-enable-signature-clash-checks=false", + // Translate capturing lambdas into anonymous JS functions rather than hoisting parameters + // and creating a named sibling function. Only affects targets which produce actual JS. + "-Xir-generate-inline-anonymous-functions" + ) + ) + } + } + } +} diff --git a/build.gradle.kts b/build.gradle.kts index 24fd03c..f31dc90 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -29,7 +29,7 @@ plugins { // alias(libs.plugins.jetbrains.compose) apply false alias(libs.plugins.compose.compiler) apply false alias(libs.plugins.spotless) apply false - id("com.jithub.build.logic") + id("com.jithub.build-logic") } allprojects { @@ -44,7 +44,7 @@ allprojects { } maven("https://jitpack.io") } - configureCommonKotlin() + apply(plugin = "com.jithub.build-support") } subprojects { @@ -69,38 +69,3 @@ gradle.taskGraph.whenReady { tasks.register("clean") { delete(rootProject.layout.buildDirectory) } - -private fun Project.configureCommonKotlin() { - tasks.withType(KotlinCompile::class.java).configureEach { - compilerOptions { - // Treat all Kotlin warnings as errors (disabled by default) - allWarningsAsErrors.set(properties["warningsAsErrors"] as? Boolean ?: false) - - freeCompilerArgs.set( - freeCompilerArgs.getOrElse(emptyList()) + listOf( - // https://kotlinlang.org/docs/whatsnew13.html#progressive-mode - "-progressive", - // https://kotlinlang.org/docs/multiplatform-expect-actual.html#expected-and-actual-classes - "-Xexpect-actual-classes" - ) - ) - } - } - - tasks.withType(KotlinJvmCompile::class.java).configureEach { - compilerOptions { - freeCompilerArgs.set( - freeCompilerArgs.getOrElse(emptyList()) + listOf( - "-Xjvm-default=all" - ) - ) - jvmTarget = Versions.jvmTarget - } - } - - // Kotlin requires the Java compatibility matches. - tasks.withType(JavaCompile::class.java).configureEach { - sourceCompatibility = Versions.javaVersion.toString() - targetCompatibility = Versions.javaVersion.toString() - } -}