Skip to content

Commit

Permalink
Kotlin Multiplatform Support (#72)
Browse files Browse the repository at this point in the history
* Compose Multiplatform

KMP support & WebSite

* 2.5.0-alpha05
  • Loading branch information
alex-tiurin authored Jun 24, 2024
1 parent 98599c3 commit 7ee3c0a
Show file tree
Hide file tree
Showing 347 changed files with 20,566 additions and 661 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/android-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ master ]

jobs:
run_tests_on_api_29:
compileKotlin:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -17,4 +17,4 @@ jobs:
java-version: '17'

- name: Compile framework
run: ./gradlew :ultron:compileDebugKotlin
run: ./gradlew compileDebugKotlin
25 changes: 25 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build and deploy docs

on:
push:
branches:
- master

jobs:
github-pages:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm install
working-directory: ./docs
- run: npm run build
working-directory: ./docs

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/build
66 changes: 66 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Publish to Maven Central

permissions:
contents: read

on:
push:
tags:
- 'v*'

jobs:
publish:
env:
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
OSSRH_STAGING_PROFILE_ID: ${{ secrets.OSSRH_STAGING_PROFILE_ID }}
OSSRH_GPG_SECRET_KEY_PASSWORD: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
OSSRH_GPG_SECRET_KEY_ID: ${{ secrets.OSSRH_GPG_SECRET_KEY_ID }}

strategy:
matrix:
include:
- target: :ultron-compose:publishToSonatype
os: ubuntu-latest
- target: :ultron-android:publishToSonatype
os: ubuntu-latest
- target: :ultron-allure:publishToSonatype
os: ubuntu-latest
- target: :ultron-common:publishToSonatype
os: ubuntu-latest
runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1

- name: Setup JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: "zulu"

- name: Setup Gradle cache
uses: actions/cache@v3
with:
path: |
~/.konan
key: ${{ runner.os }}-${{ hashFiles('**/.lock') }}

- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
passphrase: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}

- name: Gradle publish
run: ./gradlew "${{ matrix.target }}" closeAndReleaseSonatypeStagingRepository
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_TOKEN }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
OSSRH_STAGING_PROFILE_ID: ${{ secrets.OSSRH_STAGING_PROFILE_ID }}
SIGNING_KEY: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
SIGNING_PASSWORD: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
build/
/captures
.externalNativeBuild
/allure-results
/allure-results
/.kotlin
21 changes: 4 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Ultron can be easially customised and extended. Wish you exclusively stable test
<img src="https://user-images.githubusercontent.com/12834123/252498170-61e5a440-c2b5-42ea-8bfb-91ee12248422.png#gh-dark-mode-only" width=600>
</p>

## [Documentation](https://open-tool.github.io/ultron/) | [Releases](https://github.com/open-tool/ultron/releases)

## What are the benefits of using the framework?

- Exceptional support for [**Compose**](https://github.com/open-tool/ultron/wiki/Compose)
Expand Down Expand Up @@ -247,21 +249,11 @@ For the complete guide, refer to the [wiki](https://github.com/open-tool/ultron/
fun setConfig() {
UltronConfig.applyRecommended()
UltronAllureConfig.applyRecommended()
UltronComposeConfig.applyRecommended()
}
```
![allure](https://github.com/open-tool/ultron/assets/12834123/c05c813a-ece6-45e6-a04f-e1c92b82ffb1)

for Compose add 4 lines more
```kotlin
@BeforeClass @JvmStatic
fun setConfig() {
...
UltronComposeConfig.applyRecommended()
UltronComposeConfig.addListener(ScreenshotAttachListener())
UltronComposeConfig.addListener(WindowHierarchyAttachListener())
UltronComposeConfig.addListener(DetailedOperationAllureListener())
}
```
![allure compose](https://github.com/open-tool/ultron/assets/12834123/1f751f3d-fc58-4874-a850-acd9181bfb70)


Expand All @@ -274,7 +266,7 @@ repositories {
}
dependencies {
androidTestImplementation 'com.atiurin:ultron:<latest_version>'
androidTestImplementation 'com.atiurin:ultron-android:<latest_version>'
androidTestImplementation 'com.atiurin:ultron-allure:<latest_version>'
androidTestImplementation 'com.atiurin:ultron-compose:<latest_version>'
}
Expand All @@ -284,8 +276,3 @@ Please, read [gradle dependencies management](https://github.com/open-tool/ultro
## AndroidX

It is required to use AndroidX libraries. You can get some problems with Android Support ones.

## Roadmap

- https://github.com/open-tool/ultron/issues/50 Meta information for UI elements
- https://github.com/open-tool/ultron/issues/33 Screenshot testign ?
35 changes: 30 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.compose.internal.utils.getLocalProperty

buildscript {
extra.apply {
set("RELEASE_REPOSITORY_URL", "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
Expand All @@ -7,6 +9,7 @@ buildscript {
repositories {
google()
mavenCentral()
mavenLocal()
}
dependencies {
classpath(Plugins.kotlinGradle)
Expand All @@ -17,14 +20,36 @@ buildscript {
}
}

plugins {
//trick: for the same plugin versions in all sub-modules
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.jetbrainsCompose) apply false
alias(libs.plugins.kotlinJvm) apply false
alias(libs.plugins.compose.compiler) apply false
id("io.github.gradle-nexus.publish-plugin").version("2.0.0-rc-1")
}

nexusPublishing {
repositories {
sonatype {
username
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username.set(getLocalProperty("ossrhToken") ?: System.getenv("OSSRH_TOKEN"))
password.set(getLocalProperty("ossrhTokenPassword") ?: System.getenv("OSSRH_PASSWORD"))
stagingProfileId.set(getLocalProperty("sonatype.stagingProfileId") ?: System.getenv("OSSRH_STAGING_PROFILE_ID"))
}
}
}


allprojects {
repositories {
google()
mavenCentral()
mavenLocal()
gradlePluginPortal()
}
}

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
}
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
object Versions {
const val kotlin = "1.8.0"
const val kotlin = "2.0.0"
const val androidToolsBuildGradle = "8.3.1"
const val androidMavenGradlePlugin = "2.1"
const val publishPlugin = "0.13.0"
const val dokkaPlugin = "1.4.30"
const val publishPlugin = "0.29.0"
const val dokkaPlugin = "1.9.20"

const val recyclerView = "1.2.1"
const val espresso = "3.4.0"
Expand Down
133 changes: 133 additions & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import org.jetbrains.compose.ExperimentalComposeLibrary
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig

plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsCompose)
alias(libs.plugins.compose.compiler)
}

kotlin {
androidTarget {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
@OptIn(ExperimentalKotlinGradlePluginApi::class)
instrumentedTestVariant {
sourceSetTree.set(KotlinSourceSetTree.test)

dependencies {
implementation(libs.androidx.ui.test.junit4.android)
debugImplementation(libs.androidx.ui.test.manifest)
}
}
}

jvm("desktop")

// listOf(
// iosX64(),
// iosArm64(),
// iosSimulatorArm64()
// ).forEach { iosTarget ->
// iosTarget.binaries.framework {
// baseName = "ComposeApp"
// isStatic = true
// }
// }

sourceSets {
val desktopMain by getting

androidMain.dependencies {
implementation(compose.preview)
implementation(libs.androidx.activity.compose)
}
commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.ui)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.navigation.compose)
}
commonTest.dependencies {
@OptIn(ExperimentalComposeLibrary::class)
implementation(compose.uiTest)
implementation(kotlin("test"))
implementation(project(":ultron-compose"))
}
desktopMain.dependencies {
implementation(compose.desktop.currentOs)
}
// Adds the desktop test dependency
val desktopTest by getting {
dependencies {
implementation(compose.desktop.uiTestJUnit4)
implementation(compose.desktop.currentOs)
}
}
}
}

android {
namespace = "com.atiurin.samplekmp"
compileSdk = libs.versions.android.compileSdk.get().toInt()

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")

defaultConfig {
applicationId = "com.atiurin.samplekmp"
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildFeatures {
compose = true
}
// dependencies {
// debugImplementation(compose.uiTooling)
// }

}


compose.desktop {
application {
mainClass = "MainKt"

nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "com.atiurin.samplekmp"
packageVersion = "1.0.0"
}
}
}
23 changes: 23 additions & 0 deletions composeApp/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@android:style/Theme.Material.Light.NoActionBar">
<activity
android:exported="true"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|layoutDirection|locale|mcc|navigation|smallestScreenSize|touchscreen|uiMode"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Loading

0 comments on commit 7ee3c0a

Please sign in to comment.