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 #36

Merged
merged 2 commits into from
Jun 22, 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
16 changes: 2 additions & 14 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
name: Android CI

on:
push:
branches: [ "master" ]
paths-ignore:
- '.idea/**'
- '.gitattributes'
- '.github/**.json'
- '.gitignore'
- '.gitmodules'
- '**.md'
- 'LICENSE'
- 'NOTICE'
- docs
- iosApp
pull_request:
branches: [ "master" ]
paths-ignore:
Expand All @@ -27,6 +14,7 @@ on:
- 'NOTICE'
- docs
- iosApp
workflow_dispatch: { }

concurrency:
group: build-android-${{ github.ref }}
Expand All @@ -44,7 +32,7 @@ jobs:
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
distribution: 'corretto'

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
14 changes: 1 addition & 13 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
name: iOS CI

on:
push:
branches: [ "master" ]
paths-ignore:
- '.idea/**'
- '.gitattributes'
- '.github/**.json'
- '.gitignore'
- '.gitmodules'
- '**.md'
- 'LICENSE'
- 'NOTICE'
- docs
- androidApp
pull_request:
branches: [ "master" ]
paths-ignore:
Expand All @@ -27,6 +14,7 @@ on:
- 'NOTICE'
- docs
- androidApp
workflow_dispatch: { }

concurrency:
group: build-ios-${{ github.ref }}
Expand Down
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import java.util.Properties
plugins {
alias(libs.plugins.android.application)
kotlin("android")
alias(libs.plugins.cashapp.redwood)
alias(libs.plugins.compose.compiler)
id("com.jithub.build.logic")
}

Expand All @@ -19,15 +19,11 @@ android {
}

buildFeatures {
// The Redwood Gradle plugin cannot be applied to an Android project which enables Compose.
// If you are using Redwood, you do not need to set this parameter.
// compose = true
buildConfig = true
}

composeOptions {
kotlinCompilerExtensionVersion = Versions.composeCompiler
}

packaging {
resources {
excludes += Resources.excludes
Expand Down Expand Up @@ -88,6 +84,11 @@ android {
}
}

composeCompiler {
enableStrongSkippingMode = true
reportsDestination = layout.buildDirectory.dir("compose_compiler")
}

androidComponents {
onVariants(selector().withBuildType("release")) {
// Only exclude *.version files in release mode as debug mode requires
Expand Down
3 changes: 0 additions & 3 deletions build-logic/convention/src/main/kotlin/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ object Versions {
const val versionName = "$majorVersion.$minorVersion.$patchVersion"
const val versionCode = 2401

// https://developer.android.com/jetpack/androidx/releases/compose-compiler?hl=zh-cn
const val composeCompiler = "1.5.14"

// jvmToolchain
// const val jdkVersion = 17

Expand Down
88 changes: 63 additions & 25 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
@file:Suppress("UnstableApiUsage")

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
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

buildscript {
repositories {
Expand All @@ -16,6 +22,7 @@ buildscript {
gradlePluginPortal()
}
dependencies {
classpath(libs.redwood.gradle.plugin)
classpath(moko.resources.gradle.plugin)
}
}
Expand All @@ -26,7 +33,7 @@ plugins {
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.cocoapods) apply false
// alias(libs.plugins.jetbrains.compose) apply false
alias(libs.plugins.cashapp.redwood) apply false
alias(libs.plugins.compose.compiler) apply false
id("com.jithub.build.logic") apply false
}

Expand Down Expand Up @@ -60,35 +67,62 @@ tasks.register<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}

// https://github.com/cashapp/redwood/blob/trunk/build-support/src/main/kotlin/app/cash/redwood/buildsupport/RedwoodBuildPlugin.kt
private fun Project.configureCommonKotlin() {
// Kotlin requires the Java compatibility matches.
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = Versions.javaVersion.toString()
targetCompatibility = Versions.javaVersion.toString()
}

tasks.withType<KotlinCompile>().configureEach {
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(
// Enable default methods in interfaces
"-Xjvm-default=all",
// Enable context receivers
"-Xcontext-receivers",
// Enable K2 compiler
"-language-version=2.0",
"-Xsuppress-version-warnings",
// 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()
}

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).
@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlin.targets.withType(KotlinJvmTarget::class.java) {
compilerOptions {
freeCompilerArgs.set(
freeCompilerArgs.getOrElse(emptyList()) + listOf(
"-Xjdk-release=${Versions.javaVersion}"
)
)
}
}

jvmTarget.set(Versions.jvmTarget)
kotlin.targets.withType(KotlinNativeTarget::class.java) {
binaries.withType(Framework::class.java) {
linkerOpts += "-lsqlite3"
}
}
}
}
Expand All @@ -99,14 +133,18 @@ private fun Project.configureCommonKotlin() {
*/
private fun Project.configureCommonCompose() {
tasks.withType<KotlinJsCompile>().configureEach {
kotlinOptions.freeCompilerArgs += 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"
)
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"
)
)
}
}
}
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ kotlin.mpp.stability.nowarn=true
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.androidSourceSetLayoutVersion=2

# https://kotl.in/issue
kotlin.apple.xcodeCompatibility.nowarn=true

# Compose
#org.jetbrains.compose.experimental.wasm.enabled=true

Expand Down
7 changes: 4 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
kotlin = "1.9.24"
kotlin = "2.0.0"
agp = "8.2.2"
redwood = "0.11.0"
redwood = "0.12.0"

androidx-activityCompose = "1.9.0"
androidx-appcompat = "1.7.0"
Expand Down Expand Up @@ -42,6 +42,7 @@ jetbrains-compose-animation = { module = "org.jetbrains.compose.animation:animat
jetbrains-components-resources = { module = "org.jetbrains.compose.components:components-resources", version.ref = "jbr-compose" }

# Redwood: https://github.com/cashapp/redwood
redwood-gradle-plugin = { module = "app.cash.redwood:redwood-gradle-plugin", version.ref = "redwood" }
redwood-compose = { module = "app.cash.redwood:redwood-compose", version.ref = "redwood" }
redwood-composeui = { module = "app.cash.redwood:redwood-composeui", version.ref = "redwood" }
redwood-widget-compose = { module = "app.cash.redwood:redwood-widget-compose", version.ref = "redwood" }
Expand All @@ -65,7 +66,7 @@ kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref
kotlin-cocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "jbr-compose" }

cashapp-redwood = { id = "app.cash.redwood", version.ref = "redwood" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

[bundles]
asm = []
2 changes: 1 addition & 1 deletion iosApp/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ EXTERNAL SOURCES:
:path: "../shared"

SPEC CHECKSUMS:
shared: 322de44d4a2cd8a0315d0b724307402aaa406311
shared: b0aff9d3bb868970fd514cb63f47dc4df82d3eb7
SwiftFormat: d30e6e1c9a85f4bce83394af184e2c1d03032605

PODFILE CHECKSUM: c865212f162b25efab1f4c3a7c4b85bdb722c41e
Expand Down
2 changes: 1 addition & 1 deletion redwood/shared-composeui/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("jvm")
alias(libs.plugins.cashapp.redwood)
alias(libs.plugins.compose.compiler)
}

dependencies {
Expand Down
36 changes: 22 additions & 14 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree

plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.kotlin.cocoapods)
alias(libs.plugins.cashapp.redwood)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.android.library)
id("dev.icerock.mobile.multiplatform-resources")
}

kotlin {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
// https://youtrack.jetbrains.com/issue/KT-61573
targets.configureEach {
compilations.configureEach {
compileTaskProvider.configure {
compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}
}
}
}

androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = Versions.javaVersion.toString()
}
}
@Suppress("OPT_IN_USAGE")
unitTestVariant.sourceSetTree.set(KotlinSourceSetTree.test)
}

iosX64()
Expand All @@ -39,9 +42,18 @@ kotlin {
export(moko.resources)
export(moko.graphics)
}
extraSpecAttributes["swift_version"] = "[\'5.0\']" // SKIE Needs this!
}

sourceSets {
all {
languageSettings.apply {
optIn("kotlin.RequiresOptIn")
optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
optIn("kotlin.time.ExperimentalTime")
}
}

commonMain.dependencies {
// Redwood
implementation(libs.redwood.compose)
Expand Down Expand Up @@ -93,10 +105,6 @@ android {
sourceCompatibility = Versions.javaVersion
targetCompatibility = Versions.javaVersion
}

composeOptions {
kotlinCompilerExtensionVersion = Versions.composeCompiler
}
}

/* task 'testClasses' not found in project */
Expand Down
Loading
Loading