Skip to content

Commit

Permalink
Migrate to Kotlin 2.0.0 and Compose Compiler plugin (#1104)
Browse files Browse the repository at this point in the history
* Upgrate gradle to 8.8

* Migrate to Kotlin 2.0.0 and Compose Compiler plugin

* Bump Compose bom verions

* Add kotlin generated classes to the gitignore

---------

Co-authored-by: Aleksandar Apostolov <[email protected]>
  • Loading branch information
skydoves and aleksandar-apostolov authored Jun 5, 2024
1 parent 979967d commit da49f5e
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 186 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ library/.env
# Java class files
*.class

# Kotlin class files
.kotlin

# Generated files
bin/
gen/
Expand Down
1 change: 1 addition & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ java {
dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.compose.compiler.gradlePlugin)
compileOnly(libs.spotless.gradlePlugin)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,35 @@ package io.getstream.video
import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.assign
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import java.io.File
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension

/**
* Configure Compose-specific options
*/
internal fun Project.configureAndroidCompose(
commonExtension: CommonExtension<*, *, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
pluginManager.apply("org.jetbrains.kotlin.plugin.compose")
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

commonExtension.apply {
buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion =
libs.findVersion("androidxComposeCompiler").get().toString()
}

kotlinOptions {
freeCompilerArgs += buildComposeMetricsParameters() + configureComposeStabilityPath()
}
commonExtension.apply {
buildFeatures {
compose = true
}

dependencies {
val bom = libs.findLibrary("androidx-compose-bom").get()
add("implementation", platform(bom))
add("androidTestImplementation", platform(bom))
}
}

private fun Project.buildComposeMetricsParameters(): List<String> {
val metricParameters = mutableListOf<String>()
val enableMetricsProvider = project.providers.gradleProperty("enableComposeCompilerMetrics")
val relativePath = projectDir.relativeTo(rootDir)
val buildDir = layout.buildDirectory.get().asFile
val enableMetrics = (enableMetricsProvider.orNull == "true")
if (enableMetrics) {
val metricsFolder = buildDir.resolve("compose-metrics").resolve(relativePath)
metricParameters.add("-P")
metricParameters.add(
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" + metricsFolder.absolutePath
)
}

val enableReportsProvider = project.providers.gradleProperty("enableComposeCompilerReports")
val enableReports = (enableReportsProvider.orNull == "true")
if (enableReports) {
val reportsFolder = buildDir.resolve("compose-reports").resolve(relativePath)
metricParameters.add("-P")
metricParameters.add(
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" + reportsFolder.absolutePath
)
}
return metricParameters.toList()
}

private fun Project.configureComposeStabilityPath(): List<String> {
val metricParameters = mutableListOf<String>()
val stabilityConfigurationFile = rootDir.resolve("compose_compiler_config.conf")
metricParameters.add("-P")
metricParameters.add(
"plugin:androidx.compose.compiler.plugins.kotlin:stabilityConfigurationPath=" + stabilityConfigurationFile.absolutePath
)
return metricParameters.toList()
}

dependencies {
val bom = libs.findLibrary("androidx-compose-bom").get()
add("implementation", platform(bom))
add("androidTestImplementation", platform(bom))
}

extensions.configure<ComposeCompilerGradlePluginExtension> {
enableStrongSkippingMode = true
reportsDestination = layout.buildDirectory.dir("compose_compiler")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
* Configure base Kotlin with Android options
*/
internal fun Project.configureKotlinAndroid(
commonExtension: CommonExtension<*, *, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

Expand Down Expand Up @@ -44,6 +44,6 @@ internal fun Project.configureKotlinAndroid(
}
}

fun CommonExtension<*, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
fun CommonExtension<*, *, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
(this as ExtensionAware).extensions.configure("kotlinOptions", block)
}
85 changes: 43 additions & 42 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,57 @@ apply(plugin = "io.github.gradle-nexus.publish-plugin")
apply(plugin = "org.jetbrains.dokka")

buildscript {
repositories {
google()
mavenCentral()
maven("https://plugins.gradle.org/m2/")
}
repositories {
google()
mavenCentral()
maven("https://plugins.gradle.org/m2/")
}
}

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.kotlin.compatibility.validator) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.wire) apply false
alias(libs.plugins.nexus) apply false
alias(libs.plugins.google.gms) apply false
alias(libs.plugins.dokka) apply false
alias(libs.plugins.spotless) apply false
alias(libs.plugins.paparazzi) apply false
alias(libs.plugins.firebase.crashlytics) apply false
alias(libs.plugins.hilt) apply false
alias(libs.plugins.play.publisher) apply false
alias(libs.plugins.baseline.profile) apply false
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.kotlin.compatibility.validator) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.wire) apply false
alias(libs.plugins.nexus) apply false
alias(libs.plugins.google.gms) apply false
alias(libs.plugins.dokka) apply false
alias(libs.plugins.spotless) apply false
alias(libs.plugins.paparazzi) apply false
alias(libs.plugins.firebase.crashlytics) apply false
alias(libs.plugins.hilt) apply false
alias(libs.plugins.play.publisher) apply false
alias(libs.plugins.baseline.profile) apply false
}

subprojects {
if (name.startsWith("stream-video-android")) {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += listOf(
"-Xjvm-default=enable",
"-opt-in=io.getstream.video.android.core.internal.InternalStreamVideoApi"
)
}
if (name.startsWith("stream-video-android")) {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += listOf(
"-Xjvm-default=enable",
"-opt-in=io.getstream.video.android.core.internal.InternalStreamVideoApi"
)
}
}

// TODO - re-enable the core module once coordinator is stable
if (name.startsWith("stream-video-android") && !name.startsWith("stream-video-android-core")) {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += listOf(
"-Xexplicit-api=strict"
)
}
// TODO - re-enable the core module once coordinator is stable
if (name.startsWith("stream-video-android") && !name.startsWith("stream-video-android-core")) {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += listOf(
"-Xexplicit-api=strict"
)
}
}
}

tasks.register("clean")
.configure {
delete(rootProject.buildDir)
}
.configure {
delete(rootProject.buildDir)
}

apply(from = "${rootDir}/scripts/publish-root.gradle")
//apply(from = teamPropsFile("git-hooks.gradle.kts"))
Expand All @@ -62,9 +63,9 @@ apply(from = "${rootDir}/scripts/publish-root.gradle")
//}

afterEvaluate {
println("Running Add Pre Commit Git Hook Script on Build")
exec {
commandLine("cp", "./scripts/git-hooks/pre-push", "./.git/hooks")
}
println("Added pre-push Git Hook Script.")
println("Running Add Pre Commit Git Hook Script on Build")
exec {
commandLine("cp", "./scripts/git-hooks/pre-push", "./.git/hooks")
}
println("Added pre-push Git Hook Script.")
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.Login
import androidx.compose.material.icons.automirrored.filled.Logout
import androidx.compose.material.icons.filled.Call
import androidx.compose.material.icons.filled.Login
import androidx.compose.material.icons.filled.Logout
Expand Down Expand Up @@ -299,7 +301,7 @@ private fun CallJoinHeader(
if (!isProduction) {
StreamButton(
modifier = Modifier.fillMaxWidth(),
icon = Icons.Default.Logout,
icon = Icons.AutoMirrored.Filled.Logout,
style = VideoTheme.styles.buttonStyles.tertiaryButtonStyle(),
text = stringResource(id = R.string.sign_out),
onClick = {
Expand Down Expand Up @@ -489,7 +491,7 @@ private fun JoinCallForm(
)

StreamButton(
icon = Icons.Default.Login,
icon = Icons.AutoMirrored.Filled.Login,
style = VideoTheme.styles.buttonStyles.secondaryButtonStyle(),
modifier = Modifier
.padding(start = 16.dp)
Expand Down
12 changes: 7 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[versions]
androidGradlePlugin = "8.2.2"
androidGradlePlugin = "8.4.1"
cameraCamera2 = "1.3.0"
spotless = "6.21.0"
nexusPlugin = "1.3.0"
kotlin = "1.9.23"
ksp = "1.9.23-1.0.19"
kotlin = "2.0.0"
ksp = "2.0.0-1.0.21"
kotlinSerialization = "1.6.3"
kotlinSerializationConverter = "1.0.0"
kotlinxCoroutines = "1.8.0"
Expand All @@ -22,15 +22,15 @@ androidxActivity = "1.8.2"
androidxDataStore = "1.0.0"
googleService = "4.3.14"

androidxComposeBom = "2024.03.00"
androidxComposeBom = "2024.05.00"
androidxComposeCompiler = "1.5.11"
androidxComposeTracing = "1.0.0-beta01"
androidxHiltNavigation = "1.2.0"
androidxComposeNavigation = "2.7.7"
composeStableMarker = "1.0.2"

coil = "2.6.0"
landscapist = "2.3.2"
landscapist = "2.3.3"
accompanist = "0.32.0"
telephoto = "0.3.0"
audioswitch = "1.1.8"
Expand Down Expand Up @@ -199,6 +199,7 @@ google-mlkit-selfie-segmentation = { group = "com.google.mlkit", name = "segment
# Dependencies of the included build-logic
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" }
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
compose-compiler-gradlePlugin = { group = "org.jetbrains.kotlin", name = "compose-compiler-gradle-plugin", version.ref = "kotlin" }
spotless-gradlePlugin = { group = "com.diffplug.spotless", name = "spotless-plugin-gradle", version.ref = "spotless" }
androidx-camera-core = { group = "androidx.camera", name = "camera-core", version = "1.3.0" }
play-services-mlkit-barcode-scanning = { group = "com.google.android.gms", name = "play-services-mlkit-barcode-scanning", version = "18.3.0" }
Expand All @@ -214,6 +215,7 @@ kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binaryCompatabilityValidator" }
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
dokka = { id = "org.jetbrains.dokka", version.ref = "kotlinDokka" }
nexus = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexusPlugin" }
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
14 changes: 7 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -202,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
Loading

0 comments on commit da49f5e

Please sign in to comment.