Skip to content

Commit

Permalink
Update to K2 (#1006)
Browse files Browse the repository at this point in the history
- Update to Kotlin `2.0.0`
- Update to KSP `2.0.0-1.0.21`
- Update to Compose Multiplatform `1.6.10`
- Switch to the compose compiler shipped with Kotlin.

Will wait until after the next release is cut since we have a lot
already unreleased on main
  • Loading branch information
ZacSweers authored May 28, 2024
1 parent 757e570 commit 8e79b2a
Show file tree
Hide file tree
Showing 65 changed files with 962 additions and 932 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.gradle
.kotlin/
local.properties
.fleet
.idea
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Changelog
**Unreleased**
--------------

- Update to Kotlin `2.0.0`.
- Update to KSP `2.0.0-1.0.21`.
- Update Compose Multiplatform to `1.6.10`.
- Update Anvil to `2.5.0-beta09`.
- Switch to the compose compiler shipped with Kotlin.

0.21.0
------

Expand Down
13 changes: 5 additions & 8 deletions backstack/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ kotlin {
implementation(libs.turbine)
}
}
val androidMain by getting {
androidMain {
dependencies {
implementation(libs.androidx.lifecycle.viewModel.compose)
api(libs.androidx.lifecycle.viewModel)
api(libs.androidx.compose.runtime)
}
}
val commonTest by getting {
commonTest {
dependencies {
implementation(libs.kotlin.test)
implementation(libs.testing.assertk)
Expand All @@ -84,23 +84,20 @@ kotlin {
}
val commonJvmTest =
maybeCreate("commonJvmTest").apply {
dependsOn(commonTest.get())
dependencies {
implementation(libs.junit)
implementation(libs.truth)
}
}
val jvmTest by getting { dependsOn(commonJvmTest) }
jvmTest { dependsOn(commonJvmTest) }
// We use a common folder instead of a common source set because there is no commonizer
// which exposes the browser APIs across these two targets.
jsMain { kotlin.srcDir("src/browserMain/kotlin") }
val wasmJsMain by getting { kotlin.srcDir("src/browserMain/kotlin") }
wasmJsMain { kotlin.srcDir("src/browserMain/kotlin") }
}
}

// adding it here to make sure skiko is unpacked and available in web tests
// https://github.com/JetBrains/compose-multiplatform/issues/4133
compose.experimental { web.application {} }

tasks.withType<KotlinCompilationTask<*>>().configureEach {
compilerOptions {
// Need to disable, due to 'duplicate library name' warning
Expand Down
12 changes: 12 additions & 0 deletions backstack/dependencies/jvmRuntimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
androidx.annotation:annotation-jvm
androidx.annotation:annotation
androidx.arch.core:core-common
androidx.collection:collection-jvm
androidx.collection:collection
androidx.lifecycle:lifecycle-common-jvm
androidx.lifecycle:lifecycle-common
androidx.lifecycle:lifecycle-runtime-desktop
androidx.lifecycle:lifecycle-runtime
androidx.lifecycle:lifecycle-viewmodel-desktop
androidx.lifecycle:lifecycle-viewmodel
com.benasher44:uuid-jvm
com.benasher44:uuid
org.jetbrains.androidx.lifecycle:lifecycle-common
org.jetbrains.androidx.lifecycle:lifecycle-runtime-compose-desktop
org.jetbrains.androidx.lifecycle:lifecycle-runtime-compose
org.jetbrains.androidx.lifecycle:lifecycle-runtime
org.jetbrains.androidx.lifecycle:lifecycle-viewmodel
org.jetbrains.compose.annotation-internal:annotation
org.jetbrains.compose.collection-internal:collection
org.jetbrains.compose.runtime:runtime-desktop
Expand Down
101 changes: 31 additions & 70 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ import com.diffplug.gradle.spotless.SpotlessExtension
import com.diffplug.gradle.spotless.SpotlessExtensionPredeclare
import com.diffplug.spotless.LineEnding
import com.dropbox.gradle.plugins.dependencyguard.DependencyGuardPluginExtension
import com.squareup.anvil.plugin.AnvilExtension
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import java.net.URI
import org.jetbrains.compose.ComposeExtension
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.internal.KaptGenerateStubsTask
import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinMultiplatformPluginWrapper
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin
import org.jetbrains.kotlin.gradle.plugin.NATIVE_COMPILER_PLUGIN_CLASSPATH_CONFIGURATION_NAME
import org.jetbrains.kotlin.gradle.plugin.PLUGIN_CLASSPATH_CONFIGURATION_NAME
import org.jetbrains.kotlin.gradle.targets.js.ir.DefaultIncrementalSyncTask
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
Expand All @@ -50,6 +49,7 @@ plugins {
alias(libs.plugins.moshiGradlePlugin) apply false
alias(libs.plugins.dependencyGuard) apply false
alias(libs.plugins.compose) apply false
alias(libs.plugins.kotlin.plugin.compose) apply false
alias(libs.plugins.baselineprofile) apply false
alias(libs.plugins.emulatorWtf) apply false
}
Expand Down Expand Up @@ -166,12 +166,24 @@ subprojects {

val hasCompose = !project.hasProperty("circuit.noCompose")
plugins.withType<KotlinBasePlugin> {
val isMultiPlatformPlugin = this is AbstractKotlinMultiplatformPluginWrapper
tasks.withType<KotlinCompilationTask<*>>().configureEach {
// Don't double apply to stub gen
if (this is KaptGenerateStubsTask) return@configureEach
if (this is KaptGenerateStubsTask) {
// TODO due to Anvil we need to force language version 1.9
compilerOptions {
progressiveMode.set(false)
languageVersion.set(KotlinVersion.KOTLIN_1_9)
}
return@configureEach
}
val isWasmTask = name.contains("wasm", ignoreCase = true)
compilerOptions {
allWarningsAsErrors.set(true)
if (isWasmTask && this is KotlinJsCompilerOptions) {
// TODO https://youtrack.jetbrains.com/issue/KT-64115
allWarningsAsErrors.set(false)
} else {
allWarningsAsErrors.set(true)
}
if (this is KotlinJvmCompilerOptions) {
jvmTarget.set(
jvmTargetProject
Expand All @@ -195,39 +207,13 @@ subprojects {
"-Xtype-enhancement-improvements-strict-mode",
"-Xjspecify-annotations=strict",
)

// Multiplatform compose handling is handled in a later block with the compose plugin
if (hasCompose && !isMultiPlatformPlugin) {
// Flag to disable Compose's kotlin version check because they're often behind
// Or ahead
// Or if they're the same, do nothing
// It's basically just very noisy.
val composeCompilerKotlinVersion = libs.versions.compose.compiler.kotlinVersion.get()
val kotlinVersion = libs.versions.kotlin.get()
val suppressComposeKotlinVersion = kotlinVersion != composeCompilerKotlinVersion
if (suppressComposeKotlinVersion) {
freeCompilerArgs.addAll(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=$kotlinVersion",
)
}
}
}
}

progressiveMode.set(true)
}
}

if (hasCompose && !isMultiPlatformPlugin) {
// A standard android project using compose, we need to force the version again here
// separate from the ComposeExtension configuration elsewhere.
dependencies {
add(PLUGIN_CLASSPATH_CONFIGURATION_NAME, libs.androidx.compose.compiler)
add(NATIVE_COMPILER_PLUGIN_CLASSPATH_CONFIGURATION_NAME, libs.androidx.compose.compiler)
}
}

if (!project.path.startsWith(":samples") && !project.path.startsWith(":internal")) {
extensions.configure<KotlinProjectExtension> { explicitApi() }
}
Expand Down Expand Up @@ -261,6 +247,10 @@ subprojects {
module("com.google.guava:listenablefuture") { replacedBy("com.google.guava:guava") }
}

pluginManager.withPlugin("org.jetbrains.kotlin.kapt") {
tasks.withType<KaptGenerateStubsTask>().configureEach { useK2Kapt.set(true) }
}

pluginManager.withPlugin("com.vanniktech.maven.publish") {
apply(plugin = "org.jetbrains.dokka")

Expand Down Expand Up @@ -345,9 +335,6 @@ subprojects {

if (hasCompose) {
buildFeatures { compose = true }
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.version.get()
}
}

compileOptions {
Expand Down Expand Up @@ -406,40 +393,8 @@ subprojects {
dependencies.add("coreLibraryDesugaring", libs.desugarJdkLibs)
}

// Disable compose-jb Compose version checks
pluginManager.withPlugin("org.jetbrains.compose") {
// Don't run this on a pure android project
if (project.plugins.hasPlugin("org.jetbrains.kotlin.android")) return@withPlugin
configure<ComposeExtension> {
val kotlinVersion = libs.versions.kotlin.get()
// Flag to disable Compose's kotlin version check because they're often behind
// Or ahead
// Or if they're the same, do nothing
// It's basically just very noisy.
val (compilerDep, composeCompilerKotlinVersion) =
if (property("circuit.forceAndroidXComposeCompiler").toString().toBoolean()) {
// Google version
libs.androidx.compose.compiler.get().toString() to
libs.versions.compose.compiler.kotlinVersion.get()
} else {
// JB version
libs.compose.compilerJb.get().toString() to libs.versions.compose.jb.kotlinVersion.get()
}
kotlinCompilerPlugin.set(compilerDep)
val suppressComposeKotlinVersion = kotlinVersion != composeCompilerKotlinVersion
if (suppressComposeKotlinVersion) {
tasks.withType<KotlinCompilationTask<*>>().configureEach {
// Don't double apply to stub gen
if (this is KaptGenerateStubsTask) return@configureEach
compilerOptions {
freeCompilerArgs.addAll(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=$kotlinVersion",
)
}
}
}
}
apply(plugin = "org.jetbrains.kotlin.plugin.compose")
}

pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
Expand All @@ -456,7 +411,7 @@ subprojects {
// Enforce Kotlin BOM
configure<KotlinMultiplatformExtension> {
sourceSets {
val commonMain by getting {
commonMain {
dependencies {
// KGP doesn't support catalogs https://youtrack.jetbrains.com/issue/KT-55351
implementation(
Expand Down Expand Up @@ -491,4 +446,10 @@ subprojects {
// that would include benchmarks.
tasks.register("ciConnectedCheck") { dependsOn("connectedCheck") }
}

subprojects {
pluginManager.withPlugin("com.squareup.anvil") {
configure<AnvilExtension> { useKsp(contributesAndFactoryGeneration = true) }
}
}
}
14 changes: 10 additions & 4 deletions circuit-codegen-annotations/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ kotlin {
api(projects.circuitRuntimeScreen)
}
}
val commonJvm = maybeCreate("commonJvm").apply { dependencies { compileOnly(libs.hilt) } }
val androidMain by getting { dependsOn(commonJvm) }
val jvmMain by getting { dependsOn(commonJvm) }
val commonJvm =
maybeCreate("commonJvm").apply {
dependsOn(commonMain.get())
dependencies { compileOnly(libs.hilt) }
}
androidMain { dependsOn(commonJvm) }
jvmMain { dependsOn(commonJvm) }
}

targets.configureEach {
compilations.configureEach {
compilerOptions.configure { freeCompilerArgs.add("-Xexpect-actual-classes") }
compileTaskProvider.configure {
compilerOptions { freeCompilerArgs.add("-Xexpect-actual-classes") }
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.KotlinCompilation.ExitCode
import com.tschuchort.compiletesting.SourceFile
import com.tschuchort.compiletesting.SourceFile.Companion.kotlin
import com.tschuchort.compiletesting.kspArgs
import com.tschuchort.compiletesting.kspProcessorOptions
import com.tschuchort.compiletesting.kspSourcesDir
import com.tschuchort.compiletesting.symbolProcessorProviders
import java.io.File
Expand All @@ -17,7 +17,7 @@ import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.junit.Ignore
import org.junit.Test

@Suppress("LargeClass")
@Suppress("LargeClass", "RedundantVisibilityModifier")
@OptIn(ExperimentalCompilerApi::class)
class CircuitSymbolProcessorTest {
private val appScope =
Expand Down Expand Up @@ -656,7 +656,7 @@ class CircuitSymbolProcessorTest {
class FavoritesPresenter : Presenter<FavoritesScreen.State> {
@Composable
override fun present(): FavoritesScreen.State {
throw NotImplementedError()
}
}
"""
Expand Down Expand Up @@ -708,7 +708,7 @@ class CircuitSymbolProcessorTest {
class FavoritesPresenter @Inject constructor() : Presenter<FavoritesScreen.State> {
@Composable
override fun present(): FavoritesScreen.State {
throw NotImplementedError()
}
}
"""
Expand Down Expand Up @@ -774,7 +774,7 @@ class CircuitSymbolProcessorTest {
@Composable
override fun present(): FavoritesScreen.State {
throw NotImplementedError()
}
}
"""
Expand Down Expand Up @@ -841,7 +841,7 @@ class CircuitSymbolProcessorTest {
@Composable
override fun present(): FavoritesScreen.State {
throw NotImplementedError()
}
}
"""
Expand Down Expand Up @@ -906,7 +906,7 @@ class CircuitSymbolProcessorTest {
@Composable
override fun present(): FavoritesScreen.State {
throw NotImplementedError()
}
}
"""
Expand Down Expand Up @@ -1044,7 +1044,7 @@ class CircuitSymbolProcessorTest {
@Composable
override fun present(): FavoritesScreen.State {
throw NotImplementedError()
}
}
"""
Expand Down Expand Up @@ -1252,8 +1252,10 @@ class CircuitSymbolProcessorTest {
CodegenMode.HILT -> singletonComponent
}
inheritClassPath = true
symbolProcessorProviders = listOf(CircuitSymbolProcessorProvider())
kspArgs += "circuit.codegen.mode" to codegenMode.name
symbolProcessorProviders += CircuitSymbolProcessorProvider()
kspProcessorOptions += "circuit.codegen.mode" to codegenMode.name
// Necessary for KSP
languageVersion = "1.9"
}

private fun compile(vararg sourceFiles: SourceFile, codegenMode: CodegenMode): CompilationResult {
Expand Down
Loading

0 comments on commit 8e79b2a

Please sign in to comment.