diff --git a/.github/workflows/include_static_analysis.yml b/.github/workflows/include_static_analysis.yml new file mode 100644 index 0000000000..8c7ba41b41 --- /dev/null +++ b/.github/workflows/include_static_analysis.yml @@ -0,0 +1,85 @@ +name: Static Analysis + +on: + workflow_call: + +jobs: + ktlint: + runs-on: ubuntu-latest + steps: + + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: "recursive" + + - name: Setup Gradle and task/dependency caching + uses: gradle/gradle-build-action@v2 + with: + cache-read-only: false # TODO How to configure caching here? + + - name: Run Ktlint + run: ./gradlew ktlintCheck + + - name: Stash Ktlint results + if: always() + run: | + rm -rf /tmp/ktlint + rm -rf /tmp/detekt + mkdir /tmp/ktlint + mkdir /tmp/detekt + rsync -a --delete --ignore-errors examples/kmm-sample/androidApp/build/reports/ktlint/ /tmp/ktlint/example/ || true + rsync -a --delete --ignore-errors test/build/reports/ktlint/ /tmp/ktlint/test/ || true + rsync -a --delete --ignore-errors packages/cinterop/build/reports/ktlint/ /tmp/ktlint/cinterop/ || true + rsync -a --delete --ignore-errors packages/library-base/build/reports/ktlint/ /tmp/ktlint/library-base/ || true + rsync -a --delete --ignore-errors packages/library-sync/build/reports/ktlint/ /tmp/ktlint/library-sync/ || true + rsync -a --delete --ignore-errors packages/plugin-compiler/build/reports/ktlint/ /tmp/ktlint/plugin-compiler/ || true + rsync -a --delete --ignore-errors packages/gradle-plugin/build/reports/ktlint/ /tmp/ktlint/plugin-gradle/ || true + rsync -a --delete --ignore-errors benchmarks/build/reports/ktlint/ /tmp/ktlint/benchmarks/ || true + + - name: Publish Ktlint results + uses: jwgmeligmeyling/checkstyle-github-action@master + if: always() + with: + name: Ktlint Results + title: Ktlint Analyzer report + path: '/tmp/ktlint/**/*.xml' + + detekt: + runs-on: ubuntu-latest + steps: + + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: "recursive" + + - name: Setup Gradle and task/dependency caching + uses: gradle/gradle-build-action@v2 + with: + cache-read-only: false # TODO How to configure caching here? + + - name: Run Detekt + run: ./gradlew detekt + + - name: Stash Detekt results + if: always() + run: | + rm -rf /tmp/detekt + mkdir /tmp/detekt + rsync -a --delete --ignore-errors examples/kmm-sample/androidApp/build/reports/detekt/ /tmp/detekt/example/ || true + rsync -a --delete --ignore-errors test/build/reports/detekt/ /tmp/detekt/test/ || true + rsync -a --delete --ignore-errors packages/cinterop/build/reports/detekt/ /tmp/detekt/cinterop/ || true + rsync -a --delete --ignore-errors packages/library-base/build/reports/detekt/ /tmp/detekt/library-base/ || true + rsync -a --delete --ignore-errors packages/library-sync/build/reports/detekt/ /tmp/detekt/library-sync/ || true + rsync -a --delete --ignore-errors packages/plugin-compiler/build/reports/detekt/ /tmp/detekt/plugin-compiler/ || true + rsync -a --delete --ignore-errors packages/gradle-plugin/build/reports/detekt/ /tmp/detekt/plugin-gradle/ || true + rsync -a --delete --ignore-errors benchmarks/build/reports/detekt/ /tmp/detekt/benchmarks/ || true + + - name: Publish Detekt results + uses: jwgmeligmeyling/checkstyle-github-action@master + if: always() + with: + name: Detekt Results + title: Detekt Analyzer report + path: '/tmp/detekt/**/*.xml' diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 5234ecbee3..ddebd5bfa8 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,8 +1,67 @@ -name: 'PR Build' -description: 'Build and test a pull request' -"on": +name: PR Build +on: pull_request: paths-ignore: - '**.md' env: REALM_DISABLE_ANALYTICS: true +jobs: + static-analysis: + uses: ./.github/workflows/include_static_analysis.yml + + build-packages: + runs-on: ubuntu-latest + needs: static-analysis + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: "recursive" + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v1.0.4 + + # TODO I'm not sure this catches changes to our Config.kt, what is the impact? + # https://github.com/actions/setup-java#caching-packages-dependencies + - name: Setup Java 11 + uses: actions/setup-java@v3 + with: + distribution: zulu + java-version: 11 + + # TODO Default behavior is only caching from main/master. Unclear what the best caching strategy is for us. + # TODO What is the rules and limits for caching on Github + - name: Setup Gradle and task/dependency caching + uses: gradle/gradle-build-action@v2 + with: + cache-read-only: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/releases' && github.ref != 'refs/heads/feature/github-actions' }} + + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v1.12 + with: + cmake-version: '3.21.4' + + - name: Setup Ninja + uses: ashutoshvarma/setup-ninja@master + + # TODO How to do ccache caching? It is unclear what the tradeoffs are? + - name: Install ccache + uses: hendrikmuhs/ccache-action@v1.2.2 + with: + key: realm-kotlin-${{ matrix.os }} + + - name: Prepend ccache executables to the PATH + run: echo PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" >> $GITHUB_ENV + + # TOOD This matches 23.2.8568313, but what happens if we a define specific version in our build? + - name: Setup NDK + uses: nttld/setup-ndk@v1 + with: + ndk-version: r23c + + + # - name: Build packages + # working-directory: packages + # run: ./gradlew publishCIPackages --info + + diff --git a/DEPRECATED-Jenkinsfile b/DEPRECATED-Jenkinsfile index ab74827feb..455a2353cc 100644 --- a/DEPRECATED-Jenkinsfile +++ b/DEPRECATED-Jenkinsfile @@ -162,7 +162,7 @@ pipeline { stage('Tests macOS - Unit Tests') { when { expression { runTests } } steps { - testAndCollect("packages", "macosTest") + testAndCollect("packages", "cleanAllTests macosTest") } } stage('Tests Android - Unit Tests') { @@ -171,7 +171,7 @@ pipeline { withLogcatTrace( "unittest", { - testAndCollect("packages", "connectedAndroidTest") + testAndCollect("packages", "cleanAllTests connectedAndroidTest") } ) } @@ -185,7 +185,7 @@ pipeline { "integrationtest", { forwardAdbPorts() - testAndCollect("test", "connectedAndroidTest") + testAndCollect("test", "cleanAllTests connectedAndroidTest") } ) } @@ -197,7 +197,7 @@ pipeline { steps { testWithServer([ { - testAndCollect("test", "macosTest") + testAndCollect("test", "cleanAllTests macosTest") }, ]) } @@ -209,7 +209,7 @@ pipeline { // This will overwrite previous test results, but should be ok as we would not get here // if previous stages failed. { - testAndCollect("test", "macosTest -Pkotlin.native.binary.memoryModel=experimental") + testAndCollect("test", "cleanAllTests macosTest -Pkotlin.native.binary.memoryModel=experimental") }, ]) } @@ -217,10 +217,10 @@ pipeline { stage('Tests JVM') { when { expression { runTests } } steps { - testAndCollect("test", ':base:jvmTest --tests "io.realm.kotlin.test.compiler*"') - testAndCollect("test", ':base:jvmTest --tests "io.realm.kotlin.test.shared*"') + testAndCollect("test", 'cleanAllTests :base:jvmTest --tests "io.realm.kotlin.test.compiler*"') + testAndCollect("test", 'cleanAllTests :base:jvmTest --tests "io.realm.kotlin.test.shared*"') testWithServer([ - { testAndCollect("test", ':sync:jvmTest') } + { testAndCollect("test", 'cleanAllTests :sync:jvmTest') } ]) } } @@ -229,7 +229,7 @@ pipeline { steps { testWithServer([ { - testAndCollect("test", "iosTest") + testAndCollect("test", "cleanAllTests iosTest") } ]) } @@ -248,6 +248,12 @@ pipeline { runBuildMinAndroidApp() } } + stage('Test Realm Java Compatibility App') { + when { expression { runTests } } + steps { + testAndCollect("examples/realm-java-compatibility", "connectedAndroidTest") + } + } stage('Publish SNAPSHOT to Maven Central') { when { expression { shouldPublishSnapshot(version) } } steps { @@ -561,12 +567,12 @@ def forwardAdbPorts() { """ } -def testAndCollect(dir, task) { +def testAndCollect(dir, tasks) { withEnv(['PATH+USER_BIN=/usr/local/bin']) { try { sh """ pushd $dir - ./gradlew cleanAllTests $task --info --stacktrace --no-daemon + ./gradlew $tasks --info --stacktrace --no-daemon popd """ } finally { diff --git a/buildSrc/src/main/kotlin/Config.kt b/buildSrc/src/main/kotlin/Config.kt index d673910fba..b0c807206c 100644 --- a/buildSrc/src/main/kotlin/Config.kt +++ b/buildSrc/src/main/kotlin/Config.kt @@ -57,7 +57,7 @@ object Versions { const val compileSdkVersion = 31 const val buildToolsVersion = "31.0.0" const val buildTools = "7.1.0" // https://maven.google.com/web/index.html?q=gradle#com.android.tools.build:gradle - const val ndkVersion = "23.1.7779620" + const val ndkVersion = "23.2.8568313" } const val androidxBenchmarkPlugin = "1.1.0-beta04" // https://maven.google.com/web/index.html#androidx.benchmark:androidx.benchmark.gradle.plugin const val androidxStartup = "1.1.0" // https://maven.google.com/web/index.html?q=startup#androidx.startup:startup-runtime diff --git a/examples/realm-java-compatibility/app/build.gradle b/examples/realm-java-compatibility/app/build.gradle new file mode 100644 index 0000000000..ba941ea60f --- /dev/null +++ b/examples/realm-java-compatibility/app/build.gradle @@ -0,0 +1,70 @@ +/* + * Copyright 2022 Realm Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + id 'com.android.application' + id 'org.jetbrains.kotlin.android' + id 'org.jetbrains.kotlin.kapt' + id "io.realm.kotlin" +} + +apply plugin: "realm-android" + +android { + compileSdkVersion = 31 + + defaultConfig { + applicationId "io.realm.kotlin.demo.javacompatibility" + minSdk 21 + targetSdk 31 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +realm { + syncEnabled = true +} + +dependencies { + + implementation 'androidx.core:core-ktx:1.7.0' + implementation 'androidx.appcompat:appcompat:1.4.1' + implementation 'com.google.android.material:material:1.6.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + + implementation "io.realm.kotlin:library-sync:${Realm.version}" + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' +} diff --git a/examples/realm-java-compatibility/app/proguard-rules.pro b/examples/realm-java-compatibility/app/proguard-rules.pro new file mode 100644 index 0000000000..f1b424510d --- /dev/null +++ b/examples/realm-java-compatibility/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/examples/realm-java-compatibility/app/src/androidTest/java/io/realm/kotlin/demo/javacompatibility/InstrumentedTest.kt b/examples/realm-java-compatibility/app/src/androidTest/java/io/realm/kotlin/demo/javacompatibility/InstrumentedTest.kt new file mode 100644 index 0000000000..68117cd4d5 --- /dev/null +++ b/examples/realm-java-compatibility/app/src/androidTest/java/io/realm/kotlin/demo/javacompatibility/InstrumentedTest.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Realm Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.realm.kotlin.demo.javacompatibility + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 +import io.realm.Realm +import io.realm.kotlin.demo.javacompatibility.data.java.JavaRepository +import io.realm.kotlin.demo.javacompatibility.data.kotlin.KotlinRepository + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class InstrumentedTest { + + @Test + fun test() { + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + + val repositories = setOf(JavaRepository(appContext), KotlinRepository()) + for (repository in repositories) { + assertTrue(repository.count > 0) + } + } +} diff --git a/examples/realm-java-compatibility/app/src/main/AndroidManifest.xml b/examples/realm-java-compatibility/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..6e0af0f69d --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/AndroidManifest.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + diff --git a/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/MainActivity.kt b/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/MainActivity.kt new file mode 100644 index 0000000000..5db14820d0 --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/MainActivity.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2022 Realm Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.realm.kotlin.demo.javacompatibility + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import io.realm.kotlin.demo.javacompatibility.data.java.JavaRepository + +class MainActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + } +} diff --git a/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/MainApplication.kt b/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/MainApplication.kt new file mode 100644 index 0000000000..3e4339df4e --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/MainApplication.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2022 Realm Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.realm.kotlin.demo.javacompatibility + +import android.app.Application +import io.realm.Realm +import io.realm.kotlin.demo.javacompatibility.data.java.JavaRepository +import io.realm.kotlin.demo.javacompatibility.data.kotlin.KotlinRepository + +const val TAG: String = "JavaCompatibilityApp" + +class MainApplication : Application() { + + lateinit var java: JavaRepository + lateinit var kotlin: KotlinRepository + + override fun onCreate() { + super.onCreate() + java = JavaRepository(this) + kotlin = KotlinRepository() + } +} diff --git a/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/data/Repository.kt b/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/data/Repository.kt new file mode 100644 index 0000000000..7b00920bbf --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/data/Repository.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2022 Realm Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.realm.kotlin.demo.javacompatibility.data + +interface Repository { + val count: Int +} diff --git a/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/data/java/JavaRepository.kt b/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/data/java/JavaRepository.kt new file mode 100644 index 0000000000..c45a462a1e --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/data/java/JavaRepository.kt @@ -0,0 +1,56 @@ +/* + * Copyright 2022 Realm Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.realm.kotlin.demo.javacompatibility.data.java + +import android.content.Context +import android.util.Log +import io.realm.Realm +import io.realm.RealmConfiguration +import io.realm.RealmModel +import io.realm.annotations.RealmClass +import io.realm.kotlin.demo.javacompatibility.TAG +import io.realm.kotlin.demo.javacompatibility.data.Repository + +// Realm Kotlin will try to process this class if using io.realm.RealmObject so use +// io.realm.RealmModel/@RealmClass approach instead +@RealmClass +open class JavaEntity : RealmModel { + var name: String = "JAVA" +} + +class JavaRepository(appContext: Context) : Repository { + + var realm: Realm + + init { + Realm.init(appContext) + realm = Realm.getInstance( + RealmConfiguration.Builder() + .name("java.realm") + .allowWritesOnUiThread(true) + .build() + ) + realm.executeTransaction { + realm.createObject(JavaEntity::class.java) + val entities = realm.where(JavaEntity::class.java).findAll() + Log.d(TAG, "JAVA: ${entities.size}") + } + } + + override val count: Int = realm.where(JavaEntity::class.java).findAll().count() + +} diff --git a/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/data/kotlin/KotlinRepository.kt b/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/data/kotlin/KotlinRepository.kt new file mode 100644 index 0000000000..eb8c8c774e --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/data/kotlin/KotlinRepository.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Realm Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.realm.kotlin.demo.javacompatibility.data.kotlin + +import android.util.Log +import io.realm.kotlin.Realm +import io.realm.kotlin.RealmConfiguration +import io.realm.kotlin.demo.javacompatibility.TAG +import io.realm.kotlin.demo.javacompatibility.data.Repository +import io.realm.kotlin.ext.query +import io.realm.kotlin.types.RealmObject + +class KotlinEntity : RealmObject { + var name: String = "KOTLIN" +} + +class KotlinRepository: Repository { + + val realm = Realm.open(RealmConfiguration.Builder(setOf(KotlinEntity::class)).name("kotlin.realm").build()) + + init { + realm.writeBlocking { copyToRealm(KotlinEntity()) } + val entities = realm.query().find() + Log.w(TAG, "KOTLIN: ${entities.size}") + } + + override val count = realm.query().find().size +} diff --git a/examples/realm-java-compatibility/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/examples/realm-java-compatibility/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000000..7706ab9e6d --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + diff --git a/examples/realm-java-compatibility/app/src/main/res/drawable/ic_launcher_background.xml b/examples/realm-java-compatibility/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000000..07d5da9cbf --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/realm-java-compatibility/app/src/main/res/layout/activity_main.xml b/examples/realm-java-compatibility/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000000..4fa45b0cfc --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/examples/realm-java-compatibility/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/examples/realm-java-compatibility/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000000..6b78462d61 --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/examples/realm-java-compatibility/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/examples/realm-java-compatibility/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000000..6b78462d61 --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/examples/realm-java-compatibility/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/examples/realm-java-compatibility/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000000..c209e78ecd Binary files /dev/null and b/examples/realm-java-compatibility/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/examples/realm-java-compatibility/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/examples/realm-java-compatibility/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000000..b2dfe3d1ba Binary files /dev/null and b/examples/realm-java-compatibility/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/examples/realm-java-compatibility/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/examples/realm-java-compatibility/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000000..4f0f1d64e5 Binary files /dev/null and b/examples/realm-java-compatibility/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/examples/realm-java-compatibility/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/examples/realm-java-compatibility/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000000..62b611da08 Binary files /dev/null and b/examples/realm-java-compatibility/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/examples/realm-java-compatibility/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/examples/realm-java-compatibility/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000000..948a3070fe Binary files /dev/null and b/examples/realm-java-compatibility/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/examples/realm-java-compatibility/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/examples/realm-java-compatibility/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000000..1b9a6956b3 Binary files /dev/null and b/examples/realm-java-compatibility/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/examples/realm-java-compatibility/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/examples/realm-java-compatibility/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000000..28d4b77f9f Binary files /dev/null and b/examples/realm-java-compatibility/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/examples/realm-java-compatibility/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/examples/realm-java-compatibility/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000000..9287f50836 Binary files /dev/null and b/examples/realm-java-compatibility/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/examples/realm-java-compatibility/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/examples/realm-java-compatibility/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000000..aa7d6427e6 Binary files /dev/null and b/examples/realm-java-compatibility/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/examples/realm-java-compatibility/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/examples/realm-java-compatibility/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000000..9126ae37cb Binary files /dev/null and b/examples/realm-java-compatibility/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/examples/realm-java-compatibility/app/src/main/res/values-night/themes.xml b/examples/realm-java-compatibility/app/src/main/res/values-night/themes.xml new file mode 100644 index 0000000000..dfea6cffc8 --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/res/values-night/themes.xml @@ -0,0 +1,16 @@ + + + + diff --git a/examples/realm-java-compatibility/app/src/main/res/values/colors.xml b/examples/realm-java-compatibility/app/src/main/res/values/colors.xml new file mode 100644 index 0000000000..ca1931bca9 --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + diff --git a/examples/realm-java-compatibility/app/src/main/res/values/strings.xml b/examples/realm-java-compatibility/app/src/main/res/values/strings.xml new file mode 100644 index 0000000000..3280cf8ffc --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Realm Java compatibility Demo + \ No newline at end of file diff --git a/examples/realm-java-compatibility/app/src/main/res/values/themes.xml b/examples/realm-java-compatibility/app/src/main/res/values/themes.xml new file mode 100644 index 0000000000..dbe8aa5a3e --- /dev/null +++ b/examples/realm-java-compatibility/app/src/main/res/values/themes.xml @@ -0,0 +1,16 @@ + + + + diff --git a/examples/realm-java-compatibility/build.gradle.kts b/examples/realm-java-compatibility/build.gradle.kts new file mode 100644 index 0000000000..4446b68891 --- /dev/null +++ b/examples/realm-java-compatibility/build.gradle.kts @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Realm Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + extra["ciBuild"] = Realm.ciBuild + repositories { + if (extra["ciBuild"] as Boolean) { + maven(url = "file://${rootProject.rootDir.absolutePath}/../../packages/build/m2-buildrepo") + } + google() + mavenCentral() + maven(url = "https://oss.sonatype.org/content/repositories/snapshots") + } + repositories { + mavenCentral() + } + dependencies { + classpath ("io.realm:realm-gradle-plugin:10.11.0") + classpath ("io.realm.kotlin:gradle-plugin:${Realm.version}") + } +} + +allprojects { + repositories { + if (rootProject.extra["ciBuild"] as Boolean) { + maven("file://${rootProject.rootDir.absolutePath}/../../packages/build/m2-buildrepo") + } + google() + mavenCentral() + maven(url = "https://oss.sonatype.org/content/repositories/snapshots") + } +} diff --git a/examples/realm-java-compatibility/buildSrc b/examples/realm-java-compatibility/buildSrc new file mode 120000 index 0000000000..da68abaf69 --- /dev/null +++ b/examples/realm-java-compatibility/buildSrc @@ -0,0 +1 @@ +../../buildSrc \ No newline at end of file diff --git a/examples/realm-java-compatibility/gradle.properties b/examples/realm-java-compatibility/gradle.properties new file mode 100644 index 0000000000..50d48d2d76 --- /dev/null +++ b/examples/realm-java-compatibility/gradle.properties @@ -0,0 +1,39 @@ +# +# Copyright 2022 Realm Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=true diff --git a/examples/realm-java-compatibility/gradle/wrapper/gradle-wrapper.jar b/examples/realm-java-compatibility/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..e708b1c023 Binary files /dev/null and b/examples/realm-java-compatibility/gradle/wrapper/gradle-wrapper.jar differ diff --git a/examples/realm-java-compatibility/gradle/wrapper/gradle-wrapper.properties b/examples/realm-java-compatibility/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..cf53f8c27a --- /dev/null +++ b/examples/realm-java-compatibility/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue May 24 14:11:29 CEST 2022 +distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/examples/realm-java-compatibility/gradlew b/examples/realm-java-compatibility/gradlew new file mode 100755 index 0000000000..4f906e0c81 --- /dev/null +++ b/examples/realm-java-compatibility/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# 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"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/examples/realm-java-compatibility/gradlew.bat b/examples/realm-java-compatibility/gradlew.bat new file mode 100644 index 0000000000..ac1b06f938 --- /dev/null +++ b/examples/realm-java-compatibility/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "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. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +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. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/examples/realm-java-compatibility/settings.gradle.kts b/examples/realm-java-compatibility/settings.gradle.kts new file mode 100644 index 0000000000..481cc5c8fc --- /dev/null +++ b/examples/realm-java-compatibility/settings.gradle.kts @@ -0,0 +1,36 @@ +/* + * Copyright 2022 Realm Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// For local development, we use composite builds. +// For CI buils, the packages are expected to have +// been built and deployed to a local filesystem +// maven repo. We cannot reference `Realm.ciBuild` +// from buildSrc here. +if (System.getenv("JENKINS_HOME") == null) { + includeBuild("../../packages") +} + +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + maven("https://oss.sonatype.org/content/repositories/snapshots") + } +} + +rootProject.name = "Realm Java compatibility Demo" +include(":app") diff --git a/packages/build.gradle.kts b/packages/build.gradle.kts index 1eaacb8ff4..1bdc82de71 100644 --- a/packages/build.gradle.kts +++ b/packages/build.gradle.kts @@ -41,6 +41,115 @@ allprojects { } } +tasks.register("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", + // "iosSimulatorArm64", + "iosX64", + "jvm", + "macosX64", + "macosArm64", + "android", + "metadata" + ) + val mainHostTarget: Set = setOf("metadata") // "kotlinMultiplatform" + + val isMainHost: Boolean? = if (project.properties.containsKey("realm.kotlin.mainHost")) { + project.properties["realm.kotlin.mainHost"] == "true" + } else { + null + } + // Find user configured platforms (if any) + val userTargets: Set? = (project.properties["realm.kotlin.targets"] as String?)?.split(",")?.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 wantedTargets: Collection = when (isMainHost) { + true -> mainHostTarget + (userTargets ?: availableTargets) + false -> userTargets ?: (availableTargets - mainHostTarget) + null -> availableTargets + } + + // FIXME: We probably don't need to publish plugin and compiler plugins for each node? + dependsOn(":gradle-plugin:publishAllPublicationsToBuildFolderRepository") + dependsOn(":plugin-compiler:publishAllPublicationsToBuildFolderRepository") + dependsOn(":plugin-compiler-shaded:publishAllPublicationsToBuildFolderRepository") + if (wantedTargets.contains("jvm") || wantedTargets.contains("android")) { + dependsOn(":jni-swig-stub:publishAllPublicationsToBuildFolderRepository") + } + + wantedTargets.forEach { target: String -> + when(target) { + "iosArm64" -> { + dependsOn( + ":cinterop:publishIosArm64PublicationToBuildFolderRepository", + ":cinterop:publishIosSimulatorArm64PublicationToBuildFolderRepository", + ":library-base:publishIosArm64PublicationToBuildFolderRepository", + ":libary-base:publishIosSimulatorArm64PublicationToBuildFolderRepository", + ":library-sync:publishIosArm64PublicationToBuildFolderRepository", + ":library-sync:publishIosSimulatorArm64PublicationToBuildFolderRepository", + ) + } + "iosX64" -> { + dependsOn( + ":cinterop:publishIosX64PublicationToBuildFolderRepository", + ":library-base:publishIosX64PublicationToBuildFolderRepository", + ":library-sync:publishIosX64PublicationToBuildFolderRepository", + ) + } + "jvm" -> { + dependsOn( + ":cinterop:publishJvmPublicationToBuildFolderRepository", + ":library-base:publishJvmPublicationToBuildFolderRepository", + ":library-sync:publishJvmPublicationToBuildFolderRepository", + ) + } + "macos" -> { + dependsOn( + ":cinterop:publishMacosPublicationToBuildFolderRepository", + ":library-base:publishMacosPublicationToBuildFolderRepository", + ":library-sync:publishMacosPublicationToBuildFolderRepository", + ) + } + "macosArm64" -> { + dependsOn( + ":cinterop:publishMacosArm64PublicationToBuildFolderRepository", + ":library-base:publishMacosArm64PublicationToBuildFolderRepository", + ":library-sync:publishMacosArm64PublicationToBuildFolderRepository", + ) + } + "android" -> { + dependsOn( + ":cinterop:publishAndroidDebugPublicationToBuildFolderRepository", + ":cinterop:publishAndroidReleasePublicationToBuildFolderRepository", + ":library-base:publishAndroidDebugPublicationToBuildFolderRepository", + ":library-base:publishAndroidReleasePublicationToBuildFolderRepository", + ":library-sync:publishAndroidDebugPublicationToBuildFolderRepository", + ":library-sync:publishAndroidReleasePublicationToBuildFolderRepository", + ) + } + "metadata" -> { + dependsOn( + ":cinterop:publishKotlinMultiplatformPublicationToBuildFolderRepository", + ":library-base:publishKotlinMultiplatformPublicationToBuildFolderRepository", + ":library-sync:publishKotlinMultiplatformPublicationToBuildFolderRepository", + ) + } + else -> { + throw IllegalArgumentException("Unsupported target: $target") + } + } + } +} + tasks.register("uploadDokka") { dependsOn("dokkaHtmlMultiModule") group = "Release" diff --git a/packages/cinterop/build.gradle.kts b/packages/cinterop/build.gradle.kts index c43e506847..d5c0d412ae 100644 --- a/packages/cinterop/build.gradle.kts +++ b/packages/cinterop/build.gradle.kts @@ -253,25 +253,6 @@ kotlin { } } } - - // See https://kotlinlang.org/docs/reference/mpp-publish-lib.html#publish-a-multiplatform-library - // FIXME MPP-BUILD We need to revisit this when we enable building on multiple hosts. Right now it doesn't do the right thing. - /*** - * Uncommenting below will cause the aritifact to not be published for cinterop-jvm coordinate: - * > Task :cinterop:publishJvmPublicationToMavenLocal SKIPPED - Task :cinterop:publishJvmPublicationToMavenLocal in cinterop Starting - Skipping task ':cinterop:publishJvmPublicationToMavenLocal' as task onlyIf is false. - Task :cinterop:publishJvmPublicationToMavenLocal in cinterop Finished - :cinterop:publishJvmPublicationToMavenLocal (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs. - */ -// configure(listOf(targets["metadata"], jvm())) { -// mavenPublication { -// val targetPublication = this@mavenPublication -// tasks.withType() -// .matching { it.publication == targetPublication } -// .all { onlyIf { findProperty("isMainHost") == "true" } } -// } -// } } android { @@ -607,7 +588,11 @@ tasks.named("cinteropRealm_wrapperMacos") { } tasks.named("jvmMainClasses") { - dependsOn(buildJVMSharedLibs) + if (project.extra.properties["ignoreNativeLibs"] != true) { + dependsOn(buildJVMSharedLibs) + } else { + logger.warn("Ignore building native libs") + } } // Maven Central requires JavaDoc so add empty javadoc artifacts diff --git a/packages/gradle.properties b/packages/gradle.properties index 3ce658c20f..fec0e567f6 100644 --- a/packages/gradle.properties +++ b/packages/gradle.properties @@ -21,6 +21,30 @@ kotlin.mpp.stability.nowarn=true kotlin.code.style=official android.useAndroidX=true + +org.gradle.parallel=false + +# Realm Kotlin build options +# See https://kotlinlang.org/docs/multiplatform-publish-lib.html +# The main host is responsible for publishing the KMP metadata needed to lookup platform specific +# artifacts. During a publishing process, one host is _required_ to be the main host. +# If this property is commented out, the build will publish all publications regardless of what +# `realm.kotlin.targets` is. +realm.kotlin.mainHost=true + +# Which publications to publish +# Allowed values: iosArm64,iosSimulatorArm64,iosX64,jvm,macos,macosArm64,androidDebug,androidRelease +# If not set, all publications will be published +# TODO JVM target assumes macOS as default. Linux/Windows variants are assumed to have been built elsewhere. +# Allowed values: iosArm64,iosSimulatorArm64,iosX64,jvm,macos,macosArm64,androidDebug,androidRelease +# android,iosArm64,iosX64,jvm,macosX64,macosArm64,metadata +realm.kotlin.targets=android + +# If building for the JVM, which platforms should be built. +realm.kotlin.targets.jvm.linux=true +realm.kotlin.targets.jvm.macos=true +realm.kotlin.targets.jvm.windows=true + # We cannot enable hierarchical setup as common symbols are currently not visible in Android source # sets in consuming modules (https://youtrack.jetbrains.com/issue/KT-48153) #kotlin.mpp.enableGranularSourceSetsMetadata=true diff --git a/packages/library-base/build.gradle.kts b/packages/library-base/build.gradle.kts index 482f600c4f..d1c3d609e1 100644 --- a/packages/library-base/build.gradle.kts +++ b/packages/library-base/build.gradle.kts @@ -20,6 +20,7 @@ plugins { id("realm-publisher") id("org.jetbrains.dokka") } + buildscript { dependencies { classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${Versions.atomicfu}") @@ -127,17 +128,6 @@ kotlin { } } - // See https://kotlinlang.org/docs/reference/mpp-publish-lib.html#publish-a-multiplatform-library - // FIXME MPP-BUILD We need to revisit this when we enable building on multiple hosts. Right now it doesn't do the right thing. -// configure(listOf(targets["metadata"], jvm())) { -// mavenPublication { -// val targetPublication = this@mavenPublication -// tasks.withType() -// .matching { it.publication == targetPublication } -// .all { onlyIf { findProperty("isMainHost") == "true" } } -// } -// } - // Require that all methods in the API have visibility modifiers and return types. // Anything inside `io.realm.kotlin.internal.*` is considered internal regardless of their // visibility modifier and will be stripped from Dokka, but will unfortunately still @@ -248,29 +238,30 @@ tasks.withType().configureEach { } } -tasks.register("dokkaJar", Jar::class) { - val dokkaTask = "dokkaHtmlPartial" - dependsOn(dokkaTask) - archiveClassifier.set("dokka") - from(tasks.named(dokkaTask).get().outputs) -} +// tasks.register("dokkaJar", Jar::class) { +// val dokkaTask = "dokkaHtmlPartial" +// dependsOn(dokkaTask) +// archiveClassifier.set("dokka") +// from(tasks.named(dokkaTask).get().outputs) +// } val javadocJar by tasks.registering(Jar::class) { archiveClassifier.set("javadoc") } -publishing { - // See https://dev.to/kotlin/how-to-build-and-publish-a-kotlin-multiplatform-library-going-public-4a8k - publications.withType { - // Stub javadoc.jar artifact - artifact(javadocJar.get()) - } - - val common = publications.getByName("kotlinMultiplatform") as MavenPublication - // Configuration through examples/kmm-sample does not work if we do not resolve the tasks - // completely, hence the .get() below. - common.artifact(tasks.named("dokkaJar").get()) -} +// FIXME: This is currently causing a full build of native sources in cinterop. +// publishing { +// // See https://dev.to/kotlin/how-to-build-and-publish-a-kotlin-multiplatform-library-going-public-4a8k +// publications.withType { +// // Stub javadoc.jar artifact +// artifact(javadocJar.get()) +// } +// +// val common = publications.getByName("kotlinMultiplatform") as MavenPublication +// // Configuration through examples/kmm-sample does not work if we do not resolve the tasks +// // completely, hence the .get() below. +// // common.artifact(tasks.named("dokkaJar").get()) +// } // Generate code with version constant tasks.create("generateSdkVersionConstant") { diff --git a/packages/library-base/src/commonMain/kotlin/io/realm/kotlin/log/LogLevel.kt b/packages/library-base/src/commonMain/kotlin/io/realm/kotlin/log/LogLevel.kt index 3ae06580ca..2896da0996 100644 --- a/packages/library-base/src/commonMain/kotlin/io/realm/kotlin/log/LogLevel.kt +++ b/packages/library-base/src/commonMain/kotlin/io/realm/kotlin/log/LogLevel.kt @@ -14,7 +14,7 @@ import io.realm.kotlin.log.LogLevel.WTF * * @see Configuration.SharedBuilder.log */ -@Suppress("MagicNumber") +// @Suppress("MagicNumber") public enum class LogLevel(public val priority: Int) { ALL(0), TRACE(1), diff --git a/packages/library-sync/build.gradle.kts b/packages/library-sync/build.gradle.kts index f20951d1e7..f5e5989d41 100644 --- a/packages/library-sync/build.gradle.kts +++ b/packages/library-sync/build.gradle.kts @@ -20,6 +20,7 @@ plugins { id("realm-publisher") id("org.jetbrains.dokka") } + buildscript { dependencies { classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${Versions.atomicfu}") @@ -144,17 +145,6 @@ kotlin { // visibility modifier and will be stripped from Dokka, but will unfortunately still // leak into auto-complete in the IDE. explicitApi = org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode.Strict - - // See https://kotlinlang.org/docs/reference/mpp-publish-lib.html#publish-a-multiplatform-library - // FIXME MPP-BUILD We need to revisit this when we enable building on multiple hosts. Right now it doesn't do the right thing. -// configure(listOf(targets["metadata"], jvm())) { -// mavenPublication { -// val targetPublication = this@mavenPublication -// tasks.withType() -// .matching { it.publication == targetPublication } -// .all { onlyIf { findProperty("isMainHost") == "true" } } -// } -// } } // Using a custom name module for internal methods to avoid default name mangling in Kotlin compiler which uses the module @@ -249,27 +239,28 @@ tasks.withType().configureEach { } } -tasks.register("dokkaJar", Jar::class) { - val dokkaTask = "dokkaHtmlPartial" - dependsOn(dokkaTask) - archiveClassifier.set("dokka") - from(tasks.named(dokkaTask).get().outputs) -} +// tasks.register("dokkaJar", Jar::class) { +// val dokkaTask = "dokkaHtmlPartial" +// dependsOn(dokkaTask) +// archiveClassifier.set("dokka") +// from(tasks.named(dokkaTask).get().outputs) +// } val javadocJar by tasks.registering(Jar::class) { archiveClassifier.set("javadoc") } -publishing { - // See https://dev.to/kotlin/how-to-build-and-publish-a-kotlin-multiplatform-library-going-public-4a8k - publications.withType { - // Stub javadoc.jar artifact - artifact(javadocJar.get()) - } - - // TODO: configure DOKKA so that it's only published for sync and not base - val common = publications.getByName("kotlinMultiplatform") as MavenPublication -// // Configuration through examples/kmm-sample does not work if we do not resolve the tasks -// // completely, hence the .get() below. - common.artifact(tasks.named("dokkaJar").get()) -} +// FIXME: This is currently causing a full build of native sources in cinterop. +// publishing { +// // See https://dev.to/kotlin/how-to-build-and-publish-a-kotlin-multiplatform-library-going-public-4a8k +// publications.withType { +// // Stub javadoc.jar artifact +// artifact(javadocJar.get()) +// } +// +// // TODO: configure DOKKA so that it's only published for sync and not base +// val common = publications.getByName("kotlinMultiplatform") as MavenPublication +// // // Configuration through examples/kmm-sample does not work if we do not resolve the tasks +// // // completely, hence the .get() below. +// common.artifact(tasks.named("dokkaJar").get()) +// } diff --git a/packages/plugin-compiler/build.gradle.kts b/packages/plugin-compiler/build.gradle.kts index 5dfd688326..fda87c0520 100644 --- a/packages/plugin-compiler/build.gradle.kts +++ b/packages/plugin-compiler/build.gradle.kts @@ -36,7 +36,9 @@ dependencies { testImplementation("org.jetbrains.kotlin:kotlin-reflect:${Versions.kotlin}") testImplementation("com.github.tschuchortdev:kotlin-compile-testing:${Versions.kotlinCompileTesting}") // Have to be mentioned explicitly as it is not an api dependency of library - implementation(project(":cinterop")) + implementation(project(":cinterop") { + this.extra["ignoreNativeLibs"] = true + }) testImplementation(project(":library-base")) testImplementation(project(":library-sync")) }