Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin 2.0 #44

Merged
merged 3 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ plugins {
alias(libs.plugins.android.application)
kotlin("android")
alias(libs.plugins.compose.compiler)
id("com.jithub.build.logic")
}

android {
Expand Down
2 changes: 2 additions & 0 deletions androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto">

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:allowBackup="false"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand Down
6 changes: 5 additions & 1 deletion build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
108 changes: 108 additions & 0 deletions build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt
Original file line number Diff line number Diff line change
@@ -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<KotlinJsCompile>().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"
)
)
}
}
}
}
2 changes: 1 addition & 1 deletion build-logic/convention/src/main/kotlin/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget

object Versions {
const val minSdk = 23
const val targetSdk = 33
const val targetSdk = 34
const val compileSdk = 34

private const val majorVersion = 0
Expand Down
39 changes: 2 additions & 37 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -44,7 +44,7 @@ allprojects {
}
maven("https://jitpack.io")
}
configureCommonKotlin()
apply(plugin = "com.jithub.build-support")
}

subprojects {
Expand All @@ -69,38 +69,3 @@ gradle.taskGraph.whenReady {
tasks.register<Delete>("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()
}
}
1 change: 0 additions & 1 deletion shared-compose/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>

<application />
</manifest>
Loading