Skip to content

Commit

Permalink
Merge pull request #41 from stslex/dev
Browse files Browse the repository at this point in the history
libs and build process
  • Loading branch information
stslex authored Oct 27, 2024
2 parents 299a827 + 6284f70 commit 6362b58
Show file tree
Hide file tree
Showing 491 changed files with 3,479 additions and 2,912 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/build_mac_os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,29 @@ jobs:
build:

runs-on: macos-latest
timeout-minutes: 180

steps:

- name: Checkout branch
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: set up JDK 17
uses: actions/setup-java@v3
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
distribution: 'zulu'
java-version: 21

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

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- name: Set Xcode version
run: sudo xcode-select -s /Applications/Xcode_15.3.app/Contents/Developer

- name: set up LOCAL_PROPERTIES
env:
LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }}
run: echo "$LOCAL_PROPERTIES" > ./local.properties

- name: Build with Gradle
run: ./gradlew iosArm64Binaries
run: cd iosApp && xcodebuild -workspace ./iosApp.xcworkspace -scheme iosApp -configuration Debug -destination 'platform=iOS Simulator,OS=latest,name=iPhone 15' CODE_SIGNING_ALLOWED='NO'
20 changes: 11 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
*.iml
.gradle
**/build/
**/release/
xcuserdata
!src/**/build/
local.properties
.idea
.kotlin
.fleet
.DS_Store
build
captures
.externalNativeBuild
.cxx
local.properties
xcuserdata
play_config.*
keystore.*
Gemfile.lock

**/*.podspec

*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcodeproj/project.xcworkspace/
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings
.fleet
**/*.podspec
/iosApp/Podfile.lock
/iosApp/Pods
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This is a Kotlin Multiplatform project targeting Android, iOS, Desktop, Server.
* `/shared` is for the code that will be shared between all targets in the project.
The most important subfolder is `commonMain`. If preferred, you can add code to the platform-specific folders here too.

* `/composeApp` is for code that will be shared across your Compose Multiplatform applications.
* `/commonApp` is for code that will be shared across your Compose Multiplatform applications.
It contains several subfolders:
- `commonMain` is for code that’s common for all targets.
- Other folders are for Kotlin code that will be compiled for only the platform indicated in the folder name.
Expand Down
2 changes: 2 additions & 0 deletions build-logic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/.gradle
2 changes: 2 additions & 0 deletions build-logic/convention/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/.gradle
38 changes: 38 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
`kotlin-dsl`
}

group = "com.stslex.wizard.buildlogic"

dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.compose.gradlePlugin)
compileOnly(libs.ksp.gradlePlugin)
compileOnly(libs.room.gradlePlugin)
}

gradlePlugin {
plugins {
register("kotlinLibraryMultiplatform") {
id = "convention.kmp.library"
implementationClass = "KMPLibraryConventionPlugin"
}
register("kotlinApplicationMultiplatform") {
id = "convention.kmp.application"
implementationClass = "KMPApplicationConventionPlugin"
}
register("kotlinLibraryComposeMultiplatform") {
id = "convention.kmp.library.compose"
implementationClass = "KMPLibraryComposeConventionPlugin"
}
register("kotlinLibraryComposeAndroid") {
id = "convention.android.library.compose"
implementationClass = "KotlinLibraryComposePlugin"
}
register("kotlinLibraryRoom") {
id = "convention.kmp.library.room"
implementationClass = "RoomLibraryConventionPlugin"
}
}
}
36 changes: 36 additions & 0 deletions build-logic/convention/src/main/kotlin/AppExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType

internal object AppExt {

const val APP_PREFIX = "com.stslex.wizard"

/**
* Get the version catalog for the project
* */
val Project.libs: VersionCatalog
get() = extensions.getByType<VersionCatalogsExtension>().named("libs")

/**
* Find the version of the library
*/
fun VersionCatalog.findVersionInt(name: String) = findVersion(name)
.get()
.requiredVersion
.toInt()

/**
* Find the id of plugin
*/
fun VersionCatalog.findPluginId(name: String): String = findPlugin(name)
.get()
.get()
.pluginId

/**
* Find the version of the library
*/
fun VersionCatalog.findVersionString(name: String) = findVersion(name).get().toString()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import AppExt.APP_PREFIX
import AppExt.findPluginId
import AppExt.findVersionInt
import AppExt.findVersionString
import AppExt.libs
import com.android.build.api.dsl.ApplicationExtension
import com.google.devtools.ksp.gradle.KspExtension
import com.stslex.wizard.convention.configureKMPCompose
import com.stslex.wizard.convention.configureKotlin
import com.stslex.wizard.convention.configureKotlinAndroid
import com.stslex.wizard.convention.configureKotlinAndroidCompose
import com.stslex.wizard.convention.configureKotlinMultiplatform
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.compose.ComposeExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

class KMPApplicationConventionPlugin : Plugin<Project> {

override fun apply(target: Project): Unit = with(target) {
with(pluginManager) {
apply(libs.findPluginId("kotlinMultiplatform"))
apply(libs.findPluginId("kotlinCocoapods"))
apply(libs.findPluginId("androidApplication"))
apply(libs.findPluginId("jetbrainsCompose"))
apply(libs.findPluginId("composeCompiler"))
apply(libs.findPluginId("ksp"))
apply(libs.findPluginId("serialization"))
}

extensions.configure<KotlinMultiplatformExtension> {
val kspExtension = extensions.getByType<KspExtension>()
configureKotlinMultiplatform(this, kspExtension)
configureKMPCompose(
extension = this,
compose = extensions.getByType<ComposeExtension>().dependencies
)
}

extensions.configure<ApplicationExtension> {
configureKotlin()
configureKotlinAndroid(
extension = this,
isApp = true
)
configureKotlinAndroidCompose(this)
defaultConfig.apply {
applicationId = APP_PREFIX
targetSdk = libs.findVersionInt("targetSdk")
versionName = libs.findVersionString("versionName")
versionCode = libs.findVersionInt("versionCode")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import AppExt.findPluginId
import AppExt.libs
import com.android.build.api.dsl.LibraryExtension
import com.stslex.wizard.convention.configureKMPCompose
import com.stslex.wizard.convention.configureKotlin
import com.stslex.wizard.convention.configureKotlinAndroid
import com.stslex.wizard.convention.configureKotlinMultiplatform
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.compose.ComposeExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

class KMPLibraryComposeConventionPlugin : Plugin<Project> {

override fun apply(target: Project): Unit = with(target) {
with(pluginManager) {
apply(libs.findPluginId("kotlinMultiplatform"))
apply(libs.findPluginId("jetbrainsCompose"))
apply(libs.findPluginId("composeCompiler"))
apply(libs.findPluginId("kotlinCocoapods"))
apply(libs.findPluginId("androidLibrary"))
apply(libs.findPluginId("ksp"))
apply(libs.findPluginId("serialization"))
}

extensions.configure<KotlinMultiplatformExtension> {
configureKMPCompose(
extension = this,
compose = extensions.getByType<ComposeExtension>().dependencies
)
configureKotlinMultiplatform(
extension = this,
kspExtension = extensions.getByType()
)
}

extensions.configure<LibraryExtension> {
configureKotlin()
configureKotlinAndroid(this)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import AppExt.findPluginId
import AppExt.libs
import com.android.build.api.dsl.LibraryExtension
import com.stslex.wizard.convention.configureKotlin
import com.stslex.wizard.convention.configureKotlinAndroid
import com.stslex.wizard.convention.configureKotlinMultiplatform
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

class KMPLibraryConventionPlugin : Plugin<Project> {

override fun apply(target: Project): Unit = with(target) {
with(pluginManager) {
apply(libs.findPluginId("kotlinMultiplatform"))
apply(libs.findPluginId("kotlinCocoapods"))
apply(libs.findPluginId("androidLibrary"))
apply(libs.findPluginId("ksp"))
apply(libs.findPluginId("serialization"))
}

extensions.configure<KotlinMultiplatformExtension> {
configureKotlinMultiplatform(
extension = this,
kspExtension = extensions.getByType()
)
}
extensions.configure<LibraryExtension> {
configureKotlinAndroid(this)
configureKotlin()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import AppExt.findPluginId
import AppExt.libs
import com.android.build.api.dsl.LibraryExtension
import com.stslex.wizard.convention.configureKotlin
import com.stslex.wizard.convention.configureKotlinAndroidCompose
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

class KotlinLibraryComposePlugin : Plugin<Project> {

override fun apply(target: Project): Unit = with(target) {
with(pluginManager) {
apply(libs.findPluginId("androidLibrary"))
apply(libs.findPluginId("composeCompiler"))
apply(libs.findPluginId("ksp"))
}
extensions.configure<LibraryExtension> {
configureKotlin()
configureKotlinAndroidCompose(this)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import AppExt.findPluginId
import AppExt.libs
import androidx.room.gradle.RoomExtension
import com.google.devtools.ksp.gradle.KspExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

class RoomLibraryConventionPlugin : Plugin<Project> {

override fun apply(target: Project) {
with(target) {
pluginManager.apply {
apply(libs.findPluginId("room"))
apply(libs.findPluginId("ksp"))
apply(libs.findPluginId("kotlinMultiplatform"))
apply(libs.findPluginId("serialization"))
}

extensions.configure<KspExtension> {
arg("room.generateKotlin", "true")
}

extensions.configure<RoomExtension> {
// The schemas directory contains a schema file for each version of the Room database.
// This is required to enable Room auto migrations.
// See https://developer.android.com/reference/kotlin/androidx/room/AutoMigration.
schemaDirectory("$projectDir/schemas")
}

extensions.configure<KotlinMultiplatformExtension> {
dependencies {
val roomCompiler = libs.findLibrary("room-compiler").get()
add("kspAndroid", roomCompiler)
add("kspIosSimulatorArm64", roomCompiler)
add("kspIosX64", roomCompiler)
add("kspIosArm64", roomCompiler)
}
sourceSets.apply {
commonMain.dependencies {
implementation(libs.findLibrary("room-runtime").get())
implementation(libs.findLibrary("sqlite-bundled").get())
implementation(libs.findLibrary("sqlite").get())
}
}
}
}
}
}
Loading

0 comments on commit 6362b58

Please sign in to comment.