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

Merged
merged 4 commits into from
Jul 9, 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
4 changes: 2 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ jobs:
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: iosApp/Pods
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
Expand Down
9 changes: 2 additions & 7 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import java.util.Properties

plugins {
alias(libs.plugins.android.application)
kotlin("android")
alias(libs.plugins.android.application.compose)
alias(libs.plugins.compose.compiler)
kotlin("android")
}

android {
Expand Down Expand Up @@ -65,11 +65,6 @@ android {
}
}

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

dependencies {
implementation(projects.shared)
// implementation(projects.sharedCompose)
Expand Down
16 changes: 13 additions & 3 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,30 @@ dependencies {
compileOnly(libs.gradlePlugin.kotlin) {
exclude(group = "org.ow2.asm")
}
implementation(libs.bundles.asm)
compileOnly(libs.bundles.asm)
implementation(libs.gradlePlugin.spotless)
implementation(libs.gradlePlugin.compose.compiler)
}

gradlePlugin {
plugins {
val prefix = "com.jithub.gradle"
register("build-logic") {
register("buildLogic") {
id = "$prefix.build-logic"
implementationClass = "BuildLogic"
}
register("build-support") {
register("buildSupport") {
id = "$prefix.build-support"
implementationClass = "BuildSupportPlugin"
}

register("androidApplicationCompose") {
id = "com.android.application.compose"
implementationClass = "AndroidApplicationComposeConventionPlugin"
}
register("androidLibraryCompose") {
id = "com.android.library.compose"
implementationClass = "AndroidLibraryComposeConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType

/**
* Android application compose convention plugin
*
* If compose is required, then:
* ```
* plugins {
* id("com.android.application.compose")
* }
* ```
*
* If not required:
* ```
* plugins {
* id("com.android.application")
* }
* ```
*
* @constructor Create empty Android application compose convention plugin
*/
class AndroidApplicationComposeConventionPlugin : BasePlugin() {
override fun apply(target: Project) {
log("apply target: ${target.displayName}")
with(target) {
if (!plugins.hasPlugin("com.android.application")) {
pluginManager.apply("com.android.application")
}
extensions.getByType<BaseAppModuleExtension>().apply {
configureAndroidCompose(this)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import com.android.build.gradle.LibraryExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType

/**
* Android library compose convention plugin
*
* If compose is required, then:
* ```
* plugins {
* id("com.android.library.compose")
* }
* ```
*
* If not required:
* ```
* plugins {
* id("com.android.library")
* }
* ```
*
* @constructor Create empty Android library compose convention plugin
*/
class AndroidLibraryComposeConventionPlugin : BasePlugin() {
override fun apply(target: Project) {
log("apply target: ${target.displayName}")
with(target) {
if (!plugins.hasPlugin("com.android.library")) {
pluginManager.apply("com.android.library")
}
extensions.getByType<LibraryExtension>().apply {
configureAndroidCompose(this)
}
}
}
}
10 changes: 1 addition & 9 deletions build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class BuildSupportPlugin : BasePlugin() {
defaultConfig {
minSdk = Versions.minSdk
targetSdk = Versions.targetSdk
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

testOptions.animationsDisabled = true
Expand Down Expand Up @@ -302,13 +303,4 @@ class BuildSupportPlugin : BasePlugin() {
}
}
}

private fun lintConfigure(): Lint.() -> Unit = {
abortOnError = true
warningsAsErrors = false
ignoreTestSources = true
checkDependencies = true
checkReleaseBuilds = false // Full lint runs as part of 'build' task.
htmlReport = true
}
}
46 changes: 46 additions & 0 deletions build-logic/convention/src/main/kotlin/ProjectExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.Lint
import org.gradle.api.Project
import org.gradle.api.plugins.PluginContainer
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension

internal fun Project.lintConfigure(): Lint.() -> Unit = {
abortOnError = true
warningsAsErrors = false
ignoreTestSources = true
checkDependencies = true
checkReleaseBuilds = false // Full lint runs as part of 'build' task.
htmlReport = true
// baseline = rootProject.file("lint-config/lint-baseline.xml")
// lintConfig = rootProject.file("lint-config/lint-default.xml")
}

internal fun PluginContainer.hasKotlinComposePlugin() = hasPlugin("org.jetbrains.kotlin.plugin.compose")

/**
* Configure Compose-specific options
*
* @param commonExtension
* @param hasRedwood Is Redwood used?
*/
fun Project.configureAndroidCompose(
commonExtension: CommonExtension<*, *, *, *, *>,
hasRedwood: Boolean = true
) {
if (!plugins.hasKotlinComposePlugin()) {
pluginManager.apply("org.jetbrains.kotlin.plugin.compose")
}

commonExtension.apply {
if (!hasRedwood) {
// If you are using Redwood, you do not need to set this parameter.
buildFeatures.compose = true
}
}

extensions.configure<ComposeCompilerGradlePluginExtension> {
enableStrongSkippingMode.set(true)
reportsDestination.set(layout.buildDirectory.dir("compose_compiler"))
}
}
10 changes: 8 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ junit = "4.13.2"
gradlePlugin-android = { module = "com.android.tools.build:gradle", version.ref = "agp" }
gradlePlugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
gradlePlugin-spotless = "com.diffplug.spotless:spotless-plugin-gradle:6.25.0"
gradlePlugin-compose-compiler = { module = "org.jetbrains.kotlin:compose-compiler-gradle-plugin", version.ref = "kotlin" }

androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidx-core-ktx" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidx-appcompat" }
Expand Down Expand Up @@ -63,13 +64,18 @@ androidx-test-junit = { group = "androidx.test.ext", name = "junit", version.ref
junit = { group = "junit", name = "junit", version.ref = "junit" }

[plugins]
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

android-application-compose = { id = "com.android.application.compose" }
android-library-compose = { id = "com.android.library.compose" }

android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }

kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-cocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "jbr-compose" }

compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "jbr-compose" }

[bundles]
asm = []
2 changes: 1 addition & 1 deletion shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.kotlin.cocoapods)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.android.library)
alias(libs.plugins.android.library.compose)
id("dev.icerock.mobile.multiplatform-resources")
}

Expand Down