Skip to content

make compatible with Kotlin 2.1.0 #1860

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

Open
wants to merge 7 commits into
base: community
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Dolphin]
Timestamp=2025,1,23,9,58,31.491
Version=4
ViewMode=1

[Settings]
HiddenFilesShown=true
3 changes: 1 addition & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[submodule "external/core"]
[submodule "packages/external/core"]
path = packages/external/core
url = https://github.com/realm/realm-core.git
branch = su/c-api
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
## 3.2.2

* set Android targetSDK to 35
* included the publishing scripts from @PavelFedoseev https://github.com/realm/realm-kotlin/issues/1857#issuecomment-2621494944

## 3.2.1

* fixed local publishing errors (for jvm and Android)

## 3.2.0

* changed project structure to make Intellij IDE work, buildSrc is moved out of scope io.realm
* gradlew should be run in the root directory rather than packages
* testing are on dev versions, not supporting testing maven artifacts yet
* updated a few dependencies

## 3.1.0

* updated to work with Kotlin 2.1.0
* Coroutines tested with 1.10.1
* Gradle version 8.12
* Android Gradle Plugin version 8.7.3
* Minimum Android SDK: 21
* R8 version 8.7.18

## 3.0.0-SNAPSHOT (YYYY-MM-DD)

### Breaking Changes
Expand Down
11 changes: 4 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The repository can be built on Windows, although only for the JVM and Android ta

### Linux support

This repository does currently not support building on Linux from the source code.
This repository can now be built in the same way as on the Mac.


### Building and running tests
Expand All @@ -45,19 +45,17 @@ be developed and tested as a single project. For details on publishing and runni
Maven artifacts see the [Running tests against Maven artifacts](#running-tests-against-maven-artifacts)-section.

The tests are triggered from the IDE or by triggering the specific test tasks across the various
platforms with:
platforms with (in the root directory):
```sh
cd packages
./gradlew :test-base:jvmTest :test-base:connectedAndroidTest :test-base:macosTest :test-base:iosTest
./gradlew :packages:test-base:jvmTest :packages:test-base:connectedAndroidTest :packages:test-base:macosTest :packages:test-base:iosTest

# Note that running the test-sync suite requires running a local server
# (see `tools/sync_test_server/start_local_server.sh` and `tools/sync_test_server/stop_local_server.sh`)

./gradlew :test-sync:jvmTest :test-sync:connectedAndroidTest :test-sync:macosTest :test-sync:iosTest
./gradlew :packages:test-sync:jvmTest :packages:test-sync:connectedAndroidTest :packages:test-sync:macosTest :packages:test-sync:iosTest
```
You can also the test across all modules on the various platforms with
```sh
cd packages
./gradlew jvmTest connectedAndroidTest macosTest iosTest
```
But this will also trigger tests in the SDK modules.
Expand Down Expand Up @@ -91,7 +89,6 @@ repository in a local folder using the default local and test against these usin
commands:

```sh
cd packages
./gradlew publishAllPublicationsToTestRepository
./gradlew -PincludeSdkModules=false jvmTest connectedAndroidTest macosTest iosTest
```
Expand Down
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
### This fork of Realm Kotlin SDK is to make it compatible with Kotlin 2.1.0 while updating various dependencies

JVM has been tested to work the same as with builds with Kotlin 2.0.x. Android is being tested. Testing iOS and MacOS will depend on other contributors.

Unlike the forked repo, this one can be built from source on Linux.

Project structure is changed to make Intellij IDE work. gradlew needs to be run from the root directory rather than packages.

Testing are performed on the dev versions. Maven artifacts can be published (tested locally), but can not be tested upon yet.

#### This project is rebranded for publishing on maven central, and is no longer maintained. The new project is [here](https://github.com/XilinJia/krdb)

------------------------------------

> [!WARNING]
> We announced the deprecation of Atlas Device Sync + Realm SDKs in September 2024. For more information please see:
> - [SDK Deprecation](https://www.mongodb.com/docs/atlas/device-sdks/deprecation/)
> - [Device Sync Deprecation](https://www.mongodb.com/docs/atlas/app-services/sync/device-sync-deprecation/)
>
> For a version of Realm Kotlin without sync features, install version `3.0.0+` or see the `community` git branch.


<picture>
<source srcset="./images/logo-dark.svg" media="(prefers-color-scheme: dark)" alt="realm by MongoDB">
<img src="./images/logo.svg" alt="realm by MongoDB">
</picture>

[![Gradle Plugin Portal](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/io/realm/kotlin/io.realm.kotlin.gradle.plugin/maven-metadata.xml.svg?colorB=ff6b00&label=Gradle%20Plugin%20Portal)](https://plugins.gradle.org/plugin/io.realm.kotlin)
[![Maven Central](https://img.shields.io/maven-central/v/io.realm.kotlin/gradle-plugin?colorB=4dc427&label=Maven%20Central)](https://search.maven.org/artifact/io.realm.kotlin/gradle-plugin)
[![Gradle Plugin Portal](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/io/realm/kotlin/io.realm.kotlin.gradle.plugin/maven-metadata.xml.svg?colorB=ff6b00&label=Gradle%20Plugin%20Portal&versionPrefix=2)](https://plugins.gradle.org/plugin/io.realm.kotlin)
[![Maven Central](https://img.shields.io/maven-central/v/io.realm.kotlin/gradle-plugin/2.3.0?colorB=4dc427&label=Maven%20Central)](https://search.maven.org/artifact/io.realm.kotlin/gradle-plugin)
[![Kotlin](https://img.shields.io/badge/kotlin-2.0.20-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![License](https://img.shields.io/badge/License-Apache-blue.svg)](https://github.com/realm/realm-kotlin/blob/master/LICENSE)

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion benchmarks/jvmApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ jmh {
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "11"
kotlinOptions.jvmTarget = "1.8"
}
138 changes: 135 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.JvmTarget.Companion.fromTarget

/*
* Copyright 2020 Realm Inc.
*
Expand All @@ -19,6 +22,9 @@ buildscript {
repositories {
jcenter()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.0")
}
}

// Find property in either System environment or Gradle properties.
Expand Down Expand Up @@ -64,8 +70,19 @@ fun copyProperties(action: GradleBuild) {
}
}

tasks {
//allprojects {
// version = Realm.version
// group = Realm.group
//
// // Define JVM bytecode target for all Kotlin targets
// tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile> {
// compilerOptions {
// jvmTarget.set(fromTarget(Versions.kotlinJvmTarget))
// }
// }
//}

tasks {
register("ktlintCheck") {
description = "Runs ktlintCheck on all projects."
group = "Verification"
Expand Down Expand Up @@ -112,8 +129,8 @@ tasks {

// TODO Verify we can actually use these debug symbols
val archiveDebugSymbols by register("archiveDebugSymbols", Zip::class) {
archiveName = "realm-kotlin-jni-libs-unstripped-${currentVersion}.zip"
destinationDir = releaseMetaDataDir
// archiveName = "realm-kotlin-jni-libs-unstripped-${currentVersion}.zip"
// destinationDir = releaseMetaDataDir
from("${rootDir}/packages/cinterop/build/intermediates/merged_native_libs/release/out/lib") {
include("**/*.so")
}
Expand Down Expand Up @@ -175,4 +192,119 @@ tasks {
description = "Upload release metadata to S3 (Native debug symbols, version files)"
dependsOn.addAll(listOf(uploadDebugSymbols, updateS3VersionFile))
}

register<Task>("publishCIPackages") {
group = "Publishing"
description = "Publish packages that has been configured for this CI node. See `gradle.properties`."

// Figure out which targets are configured. This will impact which sub modules will be published
val availableTargets = setOf(
"iosArm64",
"iosX64",
"jvm",
"macosX64",
"macosArm64",
"android",
"metadata",
"compilerPlugin",
"gradlePlugin"
)

val mainHostTarget: Set<String> = setOf("metadata") // "kotlinMultiplatform"

val isMainHost: Boolean = project.properties["realm.kotlin.mainHost"]?.let { it == "true" } ?: false

// Find user configured platforms (if any)
val userTargets: Set<String>? = (project.properties["realm.kotlin.targets"] as String?)
?.split(",")
?.map { it.trim() }
?.filter { it.isNotEmpty() }
?.toSet()

userTargets?.forEach {
if (!availableTargets.contains(it)) {
project.logger.error("Unknown publication: $it")
throw IllegalArgumentException("Unknown publication: $it")
}
}

// Configure which platforms publications we do want to publish
val publicationTargets = (userTargets ?: availableTargets).let {
when (isMainHost) {
true -> it + mainHostTarget
false -> it - mainHostTarget
}
}

publicationTargets.forEach { target: String ->
when (target) {
"iosArm64" -> {
dependsOn(
":packages:cinterop:publishIosArm64PublicationToTestRepository",
":packages:cinterop:publishIosSimulatorArm64PublicationToTestRepository",
":packages:library-base:publishIosArm64PublicationToTestRepository",
":packages:library-base:publishIosSimulatorArm64PublicationToTestRepository",
":packages:library-sync:publishIosArm64PublicationToTestRepository",
":packages:library-sync:publishIosSimulatorArm64PublicationToTestRepository",
)
}
"iosX64" -> {
dependsOn(
":packages:cinterop:publishIosX64PublicationToTestRepository",
":packages:library-base:publishIosX64PublicationToTestRepository",
":packages:library-sync:publishIosX64PublicationToTestRepository",
)
}
"jvm" -> {
dependsOn(
":packages:jni-swig-stub:publishAllPublicationsToTestRepository",
":packages:cinterop:publishJvmPublicationToTestRepository",
":packages:library-base:publishJvmPublicationToTestRepository",
":packages:library-sync:publishJvmPublicationToTestRepository",
)
}
"macosX64" -> {
dependsOn(
":packages:cinterop:publishMacosX64PublicationToTestRepository",
":packages:library-base:publishMacosX64PublicationToTestRepository",
":packages:library-sync:publishMacosX64PublicationToTestRepository",
)
}
"macosArm64" -> {
dependsOn(
":packages:cinterop:publishMacosArm64PublicationToTestRepository",
":packages:library-base:publishMacosArm64PublicationToTestRepository",
":packages:library-sync:publishMacosArm64PublicationToTestRepository",
)
}
"android" -> {
dependsOn(
":packages:jni-swig-stub:publishAllPublicationsToTestRepository",
":packages:cinterop:publishAndroidReleasePublicationToTestRepository",
":packages:library-base:publishAndroidReleasePublicationToTestRepository",
":packages:library-sync:publishAndroidReleasePublicationToTestRepository",
)
}
"metadata" -> {
dependsOn(
":packages:cinterop:publishKotlinMultiplatformPublicationToTestRepository",
":packages:library-base:publishKotlinMultiplatformPublicationToTestRepository",
":packages:library-sync:publishKotlinMultiplatformPublicationToTestRepository",
)
}
"compilerPlugin" -> {
dependsOn(
":packages:plugin-compiler:publishAllPublicationsToTestRepository",
":packages:plugin-compiler-shaded:publishAllPublicationsToTestRepository"
)
}
"gradlePlugin" -> {
dependsOn(":packages:gradle-plugin:publishAllPublicationsToTestRepository")
}
else -> {
throw IllegalArgumentException("Unsupported target: $target")
}
}
}
}
}
12 changes: 11 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@
plugins {
`kotlin-dsl`
`kotlin-dsl-precompiled-script-plugins`
kotlin("jvm") version Versions.kotlin
}

gradlePlugin {
plugins {
register("realm-publisher") {
id = "realm-publisher"
implementationClass = "io.realm.kotlin.RealmPublishPlugin"
implementationClass = "org.realm.kotlin.RealmPublishPlugin"
}
// create("realm-compiler") { // Plugin name (used internally)
// id = "io.realm.kotlin.plugin-compiler" // Plugin ID (used to apply)
// implementationClass = "io.realm.kotlin.compiler.Registrar"
// }
}
}

Expand All @@ -44,16 +49,21 @@ repositories {
buildscript {
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}")
classpath("org.jetbrains.dokka:dokka-gradle-plugin:${Versions.dokka}") // Use the latest version
}
}

// Setup dependencies for the buildscripts consuming the precompiled plugins
// These seem to propagate to all projects including the buildSrc/ directory, which also means
// they are not allowed to set the version. It can only be set from here.
dependencies {
implementation(kotlin("gradle-plugin", version = Versions.kotlin))
implementation("io.github.gradle-nexus:publish-plugin:${Versions.nexusPublishPlugin}")
implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:${Versions.detektPlugin}")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}")
implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:${Versions.kotlin}")
implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:5.1.2")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:${Versions.dokka}")
implementation("com.android.tools:r8:${Versions.Android.r8}")
implementation("com.android.tools.build:gradle:${Versions.Android.buildTools}")
implementation(kotlin("script-runtime"))
Expand Down
Loading