Realm-java: Excluding Kotlin Std Lib dependency from Realm Android Kotlin Extension Plugin

Created on 30 May 2018  路  2Comments  路  Source: realm/realm-java

I would like to use org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.41 instead of org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.41

Is there a way to exclude org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.41 from the Realm Android Kotlin Extensions Plugin?

O-Community T-Doc

Most helpful comment

Hi @phileo
Sorry for the late reply. We use a gradle plugin because it makes it easier to setup a larger number of dependencies, but it also unfortunately also makes it a bit harder to customize.

In your case you can stop using the Realm Gradle plugin and instead setup everything manually. Like so:

Current approach:

buildscript {
    ext.kotlin_version = '1.2.41'
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "io.realm:realm-gradle-plugin:5.2.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'

New approach:

buildscript {
    ext.kotlin_version = '1.2.41'
    ext.realm_version = '5.2.0'
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "io.realm:realm-transformer:$realm_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

import io.realm.transformer.RealmTransformer
android.registerTransform(new RealmTransformer(project))

dependencies {
  api "io.realm:realm-annotations:${realm_version}"
  api("io.realm:realm-android-kotlin-extensions:${realm_version}") {
     exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk7' 
  }
  api "io.realm:realm-android-library:${realm_version}"
  kapt "io.realm:realm-annotations-processor::${realm_version}"
}

If you are using synchronized Realms realm-android-kotlin-extensions and realm-android-library needs to be suffixed with -object-server so they become: realm-android-kotlin-extensions-object-server and realm-android-library-object-server.

All 2 comments

Hi @phileo
Sorry for the late reply. We use a gradle plugin because it makes it easier to setup a larger number of dependencies, but it also unfortunately also makes it a bit harder to customize.

In your case you can stop using the Realm Gradle plugin and instead setup everything manually. Like so:

Current approach:

buildscript {
    ext.kotlin_version = '1.2.41'
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "io.realm:realm-gradle-plugin:5.2.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'

New approach:

buildscript {
    ext.kotlin_version = '1.2.41'
    ext.realm_version = '5.2.0'
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "io.realm:realm-transformer:$realm_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

import io.realm.transformer.RealmTransformer
android.registerTransform(new RealmTransformer(project))

dependencies {
  api "io.realm:realm-annotations:${realm_version}"
  api("io.realm:realm-android-kotlin-extensions:${realm_version}") {
     exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk7' 
  }
  api "io.realm:realm-android-library:${realm_version}"
  kapt "io.realm:realm-annotations-processor::${realm_version}"
}

If you are using synchronized Realms realm-android-kotlin-extensions and realm-android-library needs to be suffixed with -object-server so they become: realm-android-kotlin-extensions-object-server and realm-android-library-object-server.

The above was added to the website docs, so we can easily refer to it in the future. Closing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AAChartModel picture AAChartModel  路  3Comments

jjorian picture jjorian  路  3Comments

mithrann picture mithrann  路  3Comments

wezley98 picture wezley98  路  3Comments

Merlin1993 picture Merlin1993  路  3Comments