Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Realm Plugin setting the bytecode target to 1.8 #1514

Merged
merged 6 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* None.

### Enhancements
* None.
* Realm will no longer set the JVM bytecode to 1.8 when applying the Realm plugin. ([#1513](https://github.com/realm/realm-kotlin/issues/1513))

### Fixed
* None.
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ android {
compileSdk = Versions.Android.compileSdkVersion

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = Versions.sourceCompatibilityVersion
targetCompatibility = Versions.targetCompatibilityVersion
}

kotlinOptions {
jvmTarget = "1.8"
jvmTarget = Versions.kotlinJvmTarget
}

defaultConfig {
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ allprojects {
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = Versions.jvmTarget
kotlinOptions.jvmTarget = Versions.kotlinJvmTarget
}
}

Expand Down
5 changes: 5 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ gradlePlugin {
}
}

java {
sourceCompatibility = Versions.sourceCompatibilityVersion
targetCompatibility = Versions.targetCompatibilityVersion
}

repositories {
google()
gradlePluginPortal()
Expand Down
10 changes: 6 additions & 4 deletions buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.gradle.api.JavaVersion

/**
* Enum describing operating systems we can build on.
Expand Down Expand Up @@ -124,20 +124,22 @@ object Versions {
const val jmh = "1.34" // https://github.com/openjdk/jmh
const val jmhPlugin = "0.6.6" // https://github.com/melix/jmh-gradle-plugin
const val junit = "4.13.2" // https://mvnrepository.com/artifact/junit/junit
const val jvmTarget = "1.8"
const val kbson = "0.3.0" // https://github.com/mongodb/kbson
// When updating the Kotlin version, also remember to update /examples/min-android-sample/build.gradle.kts
const val kotlin = "1.8.21" // https://github.com/JetBrains/kotlin and https://kotlinlang.org/docs/releases.html#release-details
const val kotlinJvmTarget = "1.8" // Which JVM bytecode version is kotlin compiled to.
const val latestKotlin = "1.9.20-Beta" // https://kotlinlang.org/docs/eap.html#build-details
const val kotlinCompileTesting = "1.5.0" // https://github.com/tschuchortdev/kotlin-compile-testing
const val ktlint = "0.45.2" // https://github.com/pinterest/ktlint
const val ktor = "2.1.2" // https://github.com/ktorio/ktor
const val multidex = "2.0.1" // https://developer.android.com/jetpack/androidx/releases/multidex
const val nexusPublishPlugin = "1.1.0" // https://github.com/gradle-nexus/publish-plugin
const val okio = "3.2.0" // https://square.github.io/okio/#releases
const val relinker = "1.4.5" // https://github.com/KeepSafe/ReLinker
const val serialization = "1.4.0" // https://kotlinlang.org/docs/releases.html#release-details
const val shadowJar = "6.1.0" // https://mvnrepository.com/artifact/com.github.johnrengelman.shadow/com.github.johnrengelman.shadow.gradle.plugin?repo=gradle-plugins
const val multidex = "2.0.1" // https://developer.android.com/jetpack/androidx/releases/multidex
const val kbson = "0.3.0" // https://github.com/mongodb/kbson
val sourceCompatibilityVersion = JavaVersion.VERSION_1_8 // Language level of any Java source code.
val targetCompatibilityVersion = JavaVersion.VERSION_1_8 // Version of generated JVM bytecode from Java files.
}

// Could be actual Dependency objects
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/realm-lint.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ allprojects {

description = "Check Kotlin code style."
classpath = ktlint
jvmArgs = listOf("--add-opens=java.base/java.lang=ALL-UNNAMED")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this? for refelction?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some APIs changed or modularized after Java 11, so if you are using Java 17, ktlint will crash. This will fix it.

mainClass.set("com.pinterest.ktlint.Main")
args = listOf(
"src/**/*.kt",
Expand All @@ -74,6 +75,7 @@ allprojects {

description = "Fix Kotlin code style deviations."
classpath = ktlint
jvmArgs = listOf("--add-opens=java.base/java.lang=ALL-UNNAMED")
mainClass.set("com.pinterest.ktlint.Main")
args = listOf(
"-F",
Expand Down
4 changes: 2 additions & 2 deletions examples/kmm-sample/androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ android {
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = Versions.sourceCompatibilityVersion
targetCompatibility = Versions.targetCompatibilityVersion
}
}
2 changes: 1 addition & 1 deletion examples/kmm-sample/compose-desktop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = Versions.jvmTarget
kotlinOptions.jvmTarget = Versions.kotlinJvmTarget
}

application {
Expand Down
6 changes: 3 additions & 3 deletions examples/realm-java-compatibility/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility Versions.sourceCompatibilityVersion
targetCompatibility Versions.targetCompatibilityVersion
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = Versions.kotlinJvmTarget
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = Versions.sourceCompatibilityVersion
targetCompatibility = Versions.targetCompatibilityVersion
}
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = Versions.kotlinJvmTarget
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ allprojects {
version = Realm.version
group = Realm.group

// Define JVM bytecode target for all Kotlin targets
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "${Versions.jvmTarget}"
kotlinOptions.jvmTarget = "${Versions.kotlinJvmTarget}"
}
}

Expand Down
14 changes: 4 additions & 10 deletions packages/cinterop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ val nativeLibraryIncludesIosSimulatorArm64Release =
includeBinaries(releaseLibs.map { "$absoluteCorePath/build-simulator-arm64/lib/$it" })

kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = Versions.jvmTarget
}
}
jvm()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it getting the correct target default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

android("android") {
publishLibraryVariants("release")
}
Expand Down Expand Up @@ -344,12 +340,10 @@ android {
path = project.file("src/jvm/CMakeLists.txt")
}
}
// To avoid
// Failed to transform kotlinx-coroutines-core-jvm-1.5.0-native-mt.jar ...
// The dependency contains Java 8 bytecode. Please enable desugaring by adding the following to build.gradle

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = Versions.sourceCompatibilityVersion
targetCompatibility = Versions.targetCompatibilityVersion
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ publishing {
java {
withSourcesJar()
withJavadocJar()
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = Versions.sourceCompatibilityVersion
targetCompatibility = Versions.targetCompatibilityVersion
}

// Make version information available at runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging
import org.gradle.api.provider.Provider
import org.gradle.build.event.BuildEventsListenerRegistry
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import javax.inject.Inject

@Suppress("unused")
Expand Down Expand Up @@ -79,24 +75,11 @@ open class RealmPlugin : Plugin<Project> {
// Stand alone Android projects have not initialized kotlin plugin when applying this, so
// postpone dependency injection till after evaluation.
project.afterEvaluate {
val kotlin: Any? = project.extensions.findByName("kotlin")
// TODO AUTO-SETUP To ease configuration we could/should inject dependencies to our
// library, but await better insight into when/what to inject and supply appropriate
// opt-out options through our own extension?
// Dependencies should probably be added by source set and not by target, as
// kotlin.sourceSets.getByName("commonMain").dependencies (or "main" for Android), but
when (kotlin) {
is KotlinSingleTargetExtension<*> -> {
updateKotlinOption(kotlin.target)
}
is KotlinMultiplatformExtension -> {
kotlin.targets.all { target -> updateKotlinOption(target) }
}
else -> {
// TODO AUTO-SETUP Should we report errors? Probably an oversighted case
// TODO("Cannot 'realm-kotlin' library dependency to ${if (kotlin != null) kotlin::class.qualifiedName else "null"}")
}
}

// Create the analytics during configuration because it needs access to the project
// in order to gather project relevant information in afterEvaluate. Currently
Expand All @@ -112,16 +95,4 @@ open class RealmPlugin : Plugin<Project> {
}
}
}

private fun updateKotlinOption(target: KotlinTarget) {
target.compilations.all { compilation ->
// Setup correct compiler options
// FIXME AUTO-SETUP Are these to dangerous to apply under the hood?
when (val options = compilation.kotlinOptions) {
is KotlinJvmOptions -> {
options.jvmTarget = "1.8"
}
}
}
}
}
9 changes: 2 additions & 7 deletions packages/jni-swig-stub/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ java {
}
}

configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.create("realmWrapperJvm") {
doLast {
// If task is actually triggered (not up to date) then we should clean up the old stuff
Expand Down Expand Up @@ -70,8 +65,8 @@ realmPublish {
java {
withSourcesJar()
withJavadocJar()
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = Versions.sourceCompatibilityVersion
targetCompatibility = Versions.targetCompatibilityVersion
}

publishing {
Expand Down
7 changes: 2 additions & 5 deletions packages/library-base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,9 @@ android {
consumerProguardFiles("proguard-rules-consumer-common.pro")
}
}
// To avoid
// Failed to transform kotlinx-coroutines-core-jvm-1.5.0-native-mt.jar ...
// The dependency contains Java 8 bytecode. Please enable desugaring by adding the following to build.gradle
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = Versions.sourceCompatibilityVersion
targetCompatibility = Versions.targetCompatibilityVersion
}
// Skip BuildConfig generation as it overlaps with io.realm.kotlin.BuildConfig from realm-java
buildFeatures {
Expand Down
7 changes: 2 additions & 5 deletions packages/library-sync/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,9 @@ android {
consumerProguardFiles("proguard-rules-consumer-common.pro")
}
}
// To avoid
// Failed to transform kotlinx-coroutines-core-jvm-1.5.0-native-mt.jar ...
// The dependency contains Java 8 bytecode. Please enable desugaring by adding the following to build.gradle
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = Versions.sourceCompatibilityVersion
targetCompatibility = Versions.targetCompatibilityVersion
}
// Skip BuildConfig generation as it overlaps with io.realm.kotlin.BuildConfig from realm-java
buildFeatures {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-compiler-shaded/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ realmPublish {
java {
withSourcesJar()
withJavadocJar()
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = Versions.sourceCompatibilityVersion
targetCompatibility = Versions.targetCompatibilityVersion
}

publishing {
Expand Down
5 changes: 2 additions & 3 deletions packages/plugin-compiler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ dependencies {

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "${Versions.jvmTarget}"
freeCompilerArgs = listOf("-Xjvm-default=all-compatibility")
}
}
Expand All @@ -69,6 +68,6 @@ publishing {
java {
withSourcesJar()
withJavadocJar()
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = Versions.sourceCompatibilityVersion
targetCompatibility = Versions.targetCompatibilityVersion
}
8 changes: 2 additions & 6 deletions packages/test-base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ kotlin {
}
}
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).all {
kotlinOptions.jvmTarget = Versions.jvmTarget
}
}

// Android configuration
Expand Down Expand Up @@ -150,8 +146,8 @@ android {
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = Versions.sourceCompatibilityVersion
targetCompatibility = Versions.targetCompatibilityVersion
}

// Remove overlapping resources after adding "org.jetbrains.kotlinx:kotlinx-coroutines-test" to
Expand Down
5 changes: 2 additions & 3 deletions packages/test-sync/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ kotlin {
}
// JVM specific KotlinCompilation tasks
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).all {
kotlinOptions.jvmTarget = Versions.jvmTarget
kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
}
}
Expand Down Expand Up @@ -161,8 +160,8 @@ android {
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = Versions.sourceCompatibilityVersion
targetCompatibility = Versions.targetCompatibilityVersion
}

// Remove overlapping resources after adding "org.jetbrains.kotlinx:kotlinx-coroutines-test" to
Expand Down